Perad Posted May 21, 2007 Share Posted May 21, 2007 I have 2 columns, descriptions and page. I want to find the images where page = $page and descriptions = header. However my query doesn't appear to be checking anything after the AND statement and thus is bringing back everything whether the discription is header or not. What am i doing wrong? $sql = "SELECT * FROM images WHERE page='$page' AND descriptions='header'"; Quote Link to comment https://forums.phpfreaks.com/topic/52338-problem-with-query/ Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 can you echo $sql and post the results please Quote Link to comment https://forums.phpfreaks.com/topic/52338-problem-with-query/#findComment-258252 Share on other sites More sharing options...
Perad Posted May 21, 2007 Author Share Posted May 21, 2007 echo $sql = SELECT * FROM images WHERE page='portfolio' AND descriptions='header' echo $result = Resource id #7 edit: complete statement is as follows. $sql = "SELECT * FROM images WHERE page='$page' AND descriptions='header'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc ($result)) { $imageurl[] = $row['imagename'] . '.' . $row['type']; } Quote Link to comment https://forums.phpfreaks.com/topic/52338-problem-with-query/#findComment-258254 Share on other sites More sharing options...
AndyB Posted May 21, 2007 Share Posted May 21, 2007 and ... Quote Link to comment https://forums.phpfreaks.com/topic/52338-problem-with-query/#findComment-258259 Share on other sites More sharing options...
Perad Posted May 21, 2007 Author Share Posted May 21, 2007 Sorry, i don't understand. Quote Link to comment https://forums.phpfreaks.com/topic/52338-problem-with-query/#findComment-258264 Share on other sites More sharing options...
AndyB Posted May 21, 2007 Share Posted May 21, 2007 And what is the problem with it? You already know that the query string is what you expect (since you used to have a line to echo $sql - didn't you?). So what isn't it doing? Quote Link to comment https://forums.phpfreaks.com/topic/52338-problem-with-query/#findComment-258267 Share on other sites More sharing options...
Perad Posted May 21, 2007 Author Share Posted May 21, 2007 It is gathering all of the results where the page is portfolio instead of all the results where the page is portfolio and the description is header. This means it is returning to many results. Quote Link to comment https://forums.phpfreaks.com/topic/52338-problem-with-query/#findComment-258269 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 try this <?php $sql = "SELECT * FROM images WHERE page='$page' AND descriptions='header'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc ($result)) { $imageurl[] = $row['imagename'] . '.' . $row['type']; if($row['descriptions']!="header"){die("ERROR");} } ?> what happens Quote Link to comment https://forums.phpfreaks.com/topic/52338-problem-with-query/#findComment-258274 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.