Link to home
Create AccountLog in
Avatar of BrighteyesDesign
BrighteyesDesignFlag for Afghanistan

asked on

Inner join working in PHPmyAdmin but not on site?

I'm trying to get an inner join to work.

I'm trying to display the country name from the cities table when it matches the cityCode from the properties table.

This works fine when tested in PHPmyAdmin (in php myAdmin I'm using 303 which is a valid property id rather that %s)

SELECT City.Name, properties.cityCode FROM properties INNER JOIN City ON properties.cityCode=City.ID WHERE properties.propertyID = %s

Open in new window


User generated image
But when this is on the actual page nothing displays?

I'm using <?php echo $row_cityName['Name']; ?> to display the result.

I have also changed %s to 303 on the page with no joy.

Any ideas what is wrong here?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

I fear the issue is on the rest of the code ...
ASKER CERTIFIED SOLUTION
Avatar of mrh14852
mrh14852

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I'm all for saving time and you are right, quotes aren't absolutely necessary (all the time). On some machines they are required, others not. I simply use them just in case you have a lage project and siomething is changed in the future like what just happened to me at work. A huge database with millions of records was upgraded and an id number which used to be AI (auto inc) was changed to a random hex key generated in the php. Such a silly idea  in my opinion as I had to add more code to make sure it was unique each insert (lots and lots of them) but I was spared heaps of work as I already had the id in single quotes so I saved a lot of work not having to add them.

I wrote a small function that I pass all my queries through before they are run. It add back tics to table names and column names only if they are missing, and adds singles quotes to all values sent in (if they are missing). I have a switch "quoteNumeric=false"  as one of the arguments so if the user sets it to true, numeric values will be quoted and leaving it out will not quote them.
Maybe it's time we heard from the author. What's happening out there, have you tried any of the suggestions given you so far?
Avatar of BrighteyesDesign

ASKER

Thanks all! I figured it out in the end but can't remember exactly what it was as I tried so many things. The responses above definitiley helped!