Trying (and failing) to print out data from a SQL query

Hey,

The following SQL query does work as I’ve tried it in phpMyAdmin and it returned results, however when I plug it into my PHP page no results are displayed :frowning: I’ve shown below how I’m doing it - I’d really appreciate it if someone could let me know what am I doing wrong!

Cheers :slight_smile:

$sql = "SELECT tours.location, MAX(tourbids.bid)
FROM tourauction
LEFT OUTER JOIN tours ON tours.tourid = tourauction.tourid
LEFT OUTER JOIN tourbids ON tourbids.tourid = tourauction.tourid
GROUP BY tours.location
ORDER BY tourauction.auctionid desc LIMIT 10";
$sqlallstuff = mysql_query($sql);

while($row_gen2 = mysql_fetch_array($sqlallstuff))
{
print($row_gen2['tours.location']);
print($row_gen2['tourbids.bid']);
} 

there is no table prefixes in the result set.
you can watch contents of an array by using print_r()function;

$sqlallstuff = mysql_query($sql);
$row_gen2 = mysql_fetch_array($sqlallstuff);
echo "<pre>";
print_r($row_gen2);
echo "</pre>";

this code will give you an idea of array’s structure, so you can note the array keys.


print($row_gen2['location']);
print($row_gen2['bid']);

Oh OK, that basically fixed it - thanks very much. For some reason the print($row_gen2[‘bid’]); didn’t work, however printing location and tourid (from the SQL below) did. If I remove the MAX() from around the tourbids.bid then I can print out the bid, however with the MAX it just doesn’t print anything.

Any idea?

SELECT tours.location, MAX(tourbids.bid), tourauction.tourid
FROM tourauction
LEFT OUTER JOIN tours ON tours.tourid = tourauction.tourid
LEFT OUTER JOIN tourbids ON tourbids.tourid = tourauction.tourid
GROUP BY tours.location
ORDER BY tourauction.auctionid desc LIMIT 10

MAX(tourbids.bid) AS maxbid

Brilliant, thanks very much!