Jump to content

Iterating Through A Query & Displaying


catalyst

Recommended Posts

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....
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

[!--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 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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.