I want to query the content of multiple (6 in total, IDs 1 to 6) IDs from a mySQL database using mySQLi. After that I want to put the result ("introtext") in different DIVs. At the moment I use the following code (works perfect):
<?php
$q = $db->query("SELECT introtext FROM content WHERE id=1");
$r = $q->fetch_object();
?>
<div id="content1" class="toggle"><?php echo "$r->introtext";?></div>
<?php
$q = $db->query("SELECT introtext FROM content WHERE id=2");
$r = $q->fetch_object();
?>
<div id="content2" class="toggle"><?php echo "$r->introtext";?></div>
<?php
$q = $db->query("SELECT introtext FROM content WHERE id=3");
$r = $q->fetch_object();
?>
<div id="content3" class="toggle"><?php echo "$r->introtext";?></div>
And so on...
How can I optimize this code to query mySQL only once (put the results in array) and assign the different results into the different DIVs?
Cheers Shredder