View Single Post
Old 11-26-2012, 08:21 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,449 Times in 2,418 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
2x queries would look like so:
PHP Code:
$sMinQry 'SELECT `identifier`, MIN(`price`) AS lowest FROM myproducts GROUP BY `identifier`';
if (
$minQry mysql_query($sMinQry))
{
    
$aMins = array();
    while (
$row mysql_fetch_assoc($minQry))
    {
        
$aMins[$row['identifier']] = $row['lowest'];
    }

    
$sQry 'SELECT `identifier`, `price` FROM myproducts ORDER BY `identifier`';
    if (
$qry mysql_query($sQry))
    {
        while (
$row mysql_fetch_assoc($qry))
        {
            
printf('<tr><td title="%s">%s</td><td>%0.2f</td></tr>''Lowest Price: ' $aMins[$row['identifier']], $row['identifier'], $row['price']);
        }
    } 

Yeah I'll move this to the MySQL forum as well.
Fou-Lu is offline   Reply With Quote