display mysql records on different places in html code

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bytte
Forum Commoner
Posts: 75
Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium

display mysql records on different places in html code

Post by bytte »

I have a mysql database that has information about cd's in it. Like the bandname, the title, the label etc.

I have a website that needs to show the 8 latest cd's that were added to the database. But all in different places in the layout.




PHP:
--------------------------------------------------------------------------------

$reviews_result = mysql_query("SELECT * FROM reviews ORDER BY datetime DESC LIMIT 0,8");
while ($reviews = mysql_fetch_array($reviews_result)) {
echo $reviews['bandname'];
}

--------------------------------------------------------------------------------


This code of course shows me 8 bandnames.
But I want to call the bandnames in the HTML whenever I want to like e.g.:

<font>here some text</font>HERE BANDNAME 1<table><tr><td></td></tr></table>HERE BANDNAME 2<hr><hr><table><tr><td>HERE TITLE 3</td></tr></table>HERE BANDNAME 4.... etc.


How can I do that? I can't simply use "while" to display the same HTML 8 times cause the HTML always needs to differ. I assume it has to do with arrays but I'm not sure how to do it.

I hope this is understandable.
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

well... an array, something like this

Code: Select all

<?php

$i = 1; 
do {

$record[$i] = $row_review['cdname'];
$i++;

} while ($reviews = mysql_fetch_array($reviews_result)); 

?>
then echo it in different places...

Code: Select all

<?php echo $record['1'] ?> 

or 

<?php echo $record['5'] ?>
Post Reply