Jump to content

Archived

This topic is now archived and is closed to further replies.

catalyst

Iterating Through A Query & Displaying

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

Share this post


Link to post
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?

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

×

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.