catalyst Posted March 27, 2006 Share Posted March 27, 2006 Hi,I apologise if this has already been posted before, but i am newbie so sorry!I am trying to make a dynamic website.Atm, i am trying to develop a section on my website that reads from a database and displays the data (e.g. like news for each day). Creating the queries and connecting is not a problem.I have a template that references each field. Whatever the query pulls out, then the associated field is displayed there (e.g. there a 5 fields that need to be shown in particular parts of the template for each record). However, i want to display the template each time that there is a record in the database, with data going into the rights parts of the template for that particular record (e.g. i want it to iterate through each record, with the data from each record being shown in one section).The easiest way i could describe this is: trying to show comments left on a website (e.g. someone posts data) and all the comments are shown. I hope i have not confused anyone or needlessly complicated things. (I know i could use a CMS, but i want to develop this myself).Thank you all for your help.... Quote Link to comment https://forums.phpfreaks.com/topic/5914-iterating-through-a-query-displaying/ Share on other sites More sharing options...
shocker-z Posted March 27, 2006 Share Posted March 27, 2006 basically u would use<?php//set the query$query=mysql_query("select * from news ORDER BY date DESC");//loop through all data returned by the querywhile($row=mysql_fetch_array($query)) {//close php tags so we can use normal HTML?><- Paste your table content here using <?php echo($row['subject']); ?> and so on to echo the fields of the table out -><?php //end the loop so anything below here will always be shown e.g. page footer} ?>Is that what you ment? Quote Link to comment https://forums.phpfreaks.com/topic/5914-iterating-through-a-query-displaying/#findComment-21118 Share on other sites More sharing options...
catalyst Posted March 27, 2006 Author Share Posted March 27, 2006 [!--quoteo(post=358811:date=Mar 27 2006, 08:11 PM:name=shocker-z)--][div class=\'quotetop\']QUOTE(shocker-z @ Mar 27 2006, 08:11 PM) [snapback]358811[/snapback][/div][div class=\'quotemain\'][!--quotec--]basically u would use<?php//set the query$query=mysql_query("select * from news ORDER BY date DESC");//loop through all data returned by the querywhile($row=mysql_fetch_array($query)) {//close php tags so we can use normal HTML?><- Paste your table content here using <?php echo($row['subject']); ?> and so on to echo the fields of the table out -><?php //end the loop so anything below here will always be shown e.g. page footer} ?>Is that what you ment?[/quote]That seems to be exactly what i want....thank you very much shocker.So easy! i was trying to use all these 'counts' and other crap...you have saved me much more further grief.Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/5914-iterating-through-a-query-displaying/#findComment-21120 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.