You would store the results from the first query "somewhere" then just reuse them as and when you want, it really depends on your application structure.
Maybe a quick example would help...
PHP Code:
<?php
function get_listings()
{
static $cache = null;
if(null === $cache)
{
$sql = 'SELECT id, title, pic FROM table;';
$res = mysql_query($sql);
$cache = array();
while($record = mysql_fetch_assoc($res))
{
array_push($cache, $record);
}
}
return $cache;
}
?>
<ul>
<?php foreach(get_listings() as $listing): ?>
<li><?php echo $listing['title']; ?></li>
<?php endforeach; ?>
</ul>
<div id="gallery">
<?php foreach(get_listings() as $listing): ?>
<img src="<?php echo $listing['pic']; ?>" alt="<?php echo $listing['title']; ?>" />
<?php endforeach; ?>
</div>
Bookmarks