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']);

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!