February 26, 2013
Query works in mysqlyog query window but not in php script?
Question by humphrey
I have two tables I am selecting from them 1 I want to get the user information and 2 I want to get all images belonging to the user . but the query does not retrieve the images but in query window I get them . Also in the script if I decide to select from the images table the images are displayed but when I do the joining stuff it does not work. I know there is something am not doing well . please any help will be appreciated
Bellow is the code
$query='SELECT
tish_clientinfo.lastname, tish_clientinfo.address,
tish_clientinfo.firstname,
tish_images.image_name
FROM tish_clientinfo
INNER JOIN tish_images
ON tish_clientinfo.user_id = tish_images.user_id
WHERE user_id= '. intval($_GET['user_id']);
$result = $con->prepare($query);
$result->execute();
Answer by Starx
May be the server got confused about user_id
. Try this
$query='SELECT
tish_clientinfo.lastname, tish_clientinfo.address,
tish_clientinfo.firstname,
tish_images.image_name
FROM tish_clientinfo
INNER JOIN tish_images
ON tish_clientinfo.user_id = tish_images.user_id
WHERE tish_clientinfo.user_id= '. intval($_GET['user_id']);