ja_blackburn Posted October 11, 2009 Share Posted October 11, 2009 Hi, If i want to have a news page on my site, which displays all records of a table in descending order by date I am using the below code. I can display it all in a big table but this is a bit boring. Can I use CSS to present these records and still have them repeat like when using a table? Or is it best to just use plain old tables?? How would I add the divs to the below statement? Thanks! Here is my code... <? include'E:\domains\s\domain.com\user\private\mysql_connect.php'; mysql_select_db("pix", $con); $result = mysql_query("SELECT * FROM news_article ORDER BY date DESC"); while($row = mysql_fetch_array($result)) { echo $row['title'] ; echo $row['date'] ; echo $row['content'] ; echo $row['image_url'] ; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
smerny Posted October 11, 2009 Share Posted October 11, 2009 you can use css on the table you know? or use divs instead... how you get the data doesn't really change how you can use css/html Quote Link to comment Share on other sites More sharing options...
Dorky Posted October 11, 2009 Share Posted October 11, 2009 echo "<div class='whatever'><h3>$row['title']</h3></div> "; now weather you use class or id, h3 or h1 doesn't matter. this is just an example of how to format such. i use single quotes(as shown above) so i don't have to do all of the escaping of double quotes also cutting down on how much code the server has to render( / for every quote adds up quick). you will need to double quote the echo string. hope this helps. Quote Link to comment Share on other sites More sharing options...
ja_blackburn Posted October 12, 2009 Author Share Posted October 12, 2009 Thanks in the end i have used classes on a table. In my code below you will see that I have applied classes to the TD tag and this has been sucessful. I want to apply a class to each row that I have called news_row which has a bottom margin and border to distinguish my list of news articles. But the class I have written is not being applied to the TR tag? Here is my CSS: .news_row{ margin: 0px 0px 10px 0px; border-bottom: 1px solid #fff; } Here is the PHP: <? include'E:\domains\s\domain.com\user\private\mysql_connect.php'; mysql_select_db("pix", $con); $result = mysql_query("SELECT * FROM news_article ORDER BY date DESC"); echo "<table border='0'> <tr> <th></th> <th></th> <th></th> <th></th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr class='news_row'>"; echo "<td class='large' width='300'>" . $row['title'] . "</td>"; echo "<td class='medium' width='100'>" . $row['date'] . "</td>"; echo "<td>" . $row['content'] . "</td>"; echo "<td width='200'>" . $row['image_url'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> As always help much appreciated!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.