Jump to content


Photo

This newb needs help with Query


  • Please log in to reply
No replies to this topic

#1 skallsen

skallsen
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 26 April 2006 - 04:55 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users