Jump to content


This topic is now archived and is closed to further replies.


This newb needs help with Query

Recommended Posts

Hey all, I need your help. I have to do a join on two tables and
output data from both.

The two tables are SaleListing and Cities

SaleListing.SaleCity has the same number as Cities.CityID

I need to query and output all of the data from the SaleListing table
and just Cities.CityName (where it matches the SaleListing.SaleCity AND
$SaleCity variable).

So it would be something like this:

City Name Sale Date Sale County
Eden Prairie 01-01-2004 Hennepin

How do I get and output the data I need from both cities? I've tried
about 20 different queries but nothing is working right.

I've tried this:

$query = "select * from SaleListing sl left join Cities ct on

and this:

$query = "SELECT a.SaleCity, b.CityID, b.CityName FROM SaleListing
a,Cities b WHERE a.SaleCity=b.CityID AND a.SaleCity=$SaleCity";

$result = mysql_query($query) or die ("ERROR: " . mysql_error());

while ($record=mysql_fetch_assoc($result)) {

echo $record["b.CityName"];


but neither of them return any records. The data is there in the db and I've run other checks. The query seems to be finding data because it gets past this: if(mysql_num_rows($result)== 0) {} and displays table headers with nothing else in the table.

Help please!

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.