skallsen Posted April 26, 2006 Share Posted April 26, 2006 Hey all, I need your help. I have to do a join on two tables andoutput data from both.The two tables are SaleListing and CitiesSaleListing.SaleCity has the same number as Cities.CityIDI need to query and output all of the data from the SaleListing tableand just Cities.CityName (where it matches the SaleListing.SaleCity AND$SaleCity variable).So it would be something like this:City Name Sale Date Sale CountyEden Prairie 01-01-2004 HennepinHow do I get and output the data I need from both cities? I've triedabout 20 different queries but nothing is working right.I've tried this:$query = "select * from SaleListing sl left join Cities ct onsl.SaleCity=ct.CityId"; and this:$query = "SELECT a.SaleCity, b.CityID, b.CityName FROM SaleListinga,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! Quote Link to comment https://forums.phpfreaks.com/topic/8431-this-newb-needs-help-with-query/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.