shogunJ Posted July 6, 2008 Share Posted July 6, 2008 Hey my first post, Firstly I'm still quite new to php/mysql and I've been doing as much homework as I can to pick things up smoothly, however I've hit a snag and would greatly appreciate some advice I've created a table in my database which I plan to keep news posts in, for instance the table has the fields 'title' 'content' 'author' and 'dateposted'. What I really wanted to do was to present each news post in a forum style... Title 1 content content content posted: Jan 01 Title 2 content content content posted: Jan 03 etc etc, does php offer a 'for each' loop? I didnt want to use an auto number as when I delete posts, this may mess up the order etc. Sorry if this has been quite a lot to read, just wanted to give as much detail as I could, thanks in advance all !! Link to comment https://forums.phpfreaks.com/topic/113489-data-presentation-help/ Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 Every article should have a unique ID. Who cares if it's "out of order" every once in a while when you delete something? And yes, PHP has a foreach loop....you could have googled that. Link to comment https://forums.phpfreaks.com/topic/113489-data-presentation-help/#findComment-583126 Share on other sites More sharing options...
Psycho Posted July 6, 2008 Share Posted July 6, 2008 Yes, there is a foreach loop in PHP. But, for this you would want to use a while loop for displaying records from a database query. Example: <?php $query = "SELCT * FROM table ORDER BY dateposted"; $result = mysql_query($query) or die (mysql_error()); while ($post = mysql_fetch_assoc($result)) { echo $post['title'] . "<br>\n"; echo $post['content'] . "<br>\n"; echo "Posted: " . $post['dateposted'] . "<br>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/113489-data-presentation-help/#findComment-583130 Share on other sites More sharing options...
shogunJ Posted July 6, 2008 Author Share Posted July 6, 2008 oh ok i think i get it, thanks mjdamato Link to comment https://forums.phpfreaks.com/topic/113489-data-presentation-help/#findComment-583132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.