View Single Post
Old 11-26-2012, 07:33 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 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
You can use the title attribute.
For the lowest price, that would best be done when selecting from the database using the MIN() function. Group by the identifier, and it will pull the minimum price.
Can't work without any data, but that would look something like:
PHP Code:
$sQry 'SELECT `identifier`, `price`, MIN(`price`) AS lowest FROM myproducts GROUP BY `identifier` 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: ' $row['lowest'], $row['identifier'], $row['price']);
    }

For example.
Take note though that this will only pull the lowest of the returned resultset, so if you limit it you will have skewed results. To pull from the entire table all the time, either use a second query or use a sub select query within the select. The SQL guys would be able to tell you which is better (I'd expect 2x queries to be better than 1x query with a nested select).
Fou-Lu is offline   Reply With Quote