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'"; 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 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']; } 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 ... 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. 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? 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. 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 Link to comment https://forums.phpfreaks.com/topic/52338-problem-with-query/#findComment-258274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.