Hello I have a simple php script that retreives information from a database and inserts it into an html table. How would I apply css to this script so that the output isn't so plain?Thank You. <?php include("passwords_db.inc"); include("connect_mysql.inc"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql) or die("Couldn't execute QUERY."); echo '<table align="center"border="1"> <tr> <td> firstname</td> <td> lastname</td><td>email</td><td>username</td><td>mailing address</td><td>city</td><td>state</td><td>phone</td><td>zipcode</td></tr>'; while ($row=mysql_fetch_array($result,MYSQL_ASSOC)) echo '<tr><td>'. $row['firstname'].'</td>'. '<td>'.$row['lastname'].'</td>'. '<td>'.$row['email'].'</td>'. '<td>'.$row['user'].'</td>'. '<td>'.$row['address'].'</td>'. '<td>'.$row['city'].'</td>'. '<td>'.$row['state'].'</td>'. '<td>'.$row['area'].$row['prefix'].$row['number'].'</td>'. '<td>'.$row['zipcode'].'</td></tr>'; ?>
Hello rojojat, First of all is this PHP codes embedded into already existing HTML file or its just the result HTML page, if it is the second option then you need to make it as a complete HTML page by including <HTML><BODY> open and close tag. Now include the CSS file in header tag in either option. Create a CSS class for your TABLE and put on whatever styles you are looking for. You can also create multiple classes for multiple options eg. TR TD DIV etc. Regards, Gonzo
add this before "<?php" <style> body { font-family:Trebuchet MS,Helvetica,Arial,sans-serif; } ... etc .. etc ... </style> <html>, <body> and other stuff are not necessary
<?php include("passwords_db.inc"); include("connect_mysql.inc"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql) or die("Couldn't execute QUERY."); include("table_styles.css"); /* Make a seperate file called this and store it in the same directory */ echo '<table align="center"border="1"> <tr> <td> firstname</td> <td> lastname</td><td>email</td><td>username</td><td>mailing address</td><td>city</td><td>state</td><td>phone</td><td>zipcode</td></tr>'; while ($row=mysql_fetch_array($result,MYSQL_ASSOC)) echo '<tr><td>'. $row['firstname'].'</td>'. '<td>'.$row['lastname'].'</td>'. '<td>'.$row['email'].'</td>'. '<td>'.$row['user'].'</td>'. '<td>'.$row['address'].'</td>'. '<td>'.$row['city'].'</td>'. '<td>'.$row['state'].'</td>'. '<td>'.$row['area'].$row['prefix'].$row['number'].'</td>'. '<td>'.$row['zipcode'].'</td></tr>'; ?>
Thank You everyone, beezzee, your way works. I tried doing include("table_styles.css"); but it just displayed the style sheet contents at the top of the page.
That's becuase it tried to read the style sheet like a PHP file, since it wasn't a PHP file it assumed it was plain text and just spit it out.
To link to an external CSS file, you have to put this code between your <head> tags: <link rel="stylesheet" type="text/css" href="FILENAME.css" />
I see! Well if your problem is solved fine otherwise you can send me a PM and I will explain you in detail how to do it. Gonzo