Jump to content


Photo

Iterating Through A Query & Displaying


  • Please log in to reply
2 replies to this topic

#1 catalyst

catalyst
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 March 2006 - 09:00 AM

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....

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 27 March 2006 - 09:11 AM

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 query
while($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?
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 catalyst

catalyst
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 March 2006 - 09:35 AM

[!--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) View Post[/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 query
while($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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users