Page 1 of 1

display mysql records on different places in html code

Posted: Sun Nov 23, 2003 8:20 am
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.

Posted: Sun Nov 23, 2003 8:32 am
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'] ?>