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.
$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.$reviews_result = mysql_query("SELECT * FROM reviews ORDER BY datetime DESC LIMIT 0,8");
while ($reviews = mysql_fetch_array($reviews_result)) {
$bandname[] = $reviews['bandname'];
}
then in your html you can call which ever bandname you want by just echo'ing the part of the array.
echo $bandname[0] will echo the first band
echo $bandname[1] will do the second one
echo $bandname[7] will echo the eighth one. get it? just remember the first one always starts with a zero.Thanks Scoutt, the mystical Guru.
I knew it was simple, but I hadn't done it before so I couldn't find out how to code it.
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.
$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.$reviews_result = mysql_query("SELECT * FROM reviews ORDER BY datetime DESC LIMIT 0,8");
while ($reviews = mysql_fetch_array($reviews_result)) {
$bandname[] = $reviews['bandname'];
}
then in your html you can call which ever bandname you want by just echo'ing the part of the array.
echo $bandname[0] will echo the first band
echo $bandname[1] will do the second one
echo $bandname[7] will echo the eighth one. get it? just remember the first one always starts with a zero.Thanks Scoutt, the mystical Guru.
I knew it was simple, but I hadn't done it before so I couldn't find out how to code it.