Jump to content

This newb needs help with Query


skallsen

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
sl.SaleCity=ct.CityId";

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"];
}

exit;

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.