Michan Posted December 4, 2007 Share Posted December 4, 2007 Hi everyone, I'm trying to run a query with more than one WHERE. $gettopics = mysql_query('SELECT * FROM topics WHERE topics.systems LIKE "'.$system.'" OR topics.topicid = '.$topic.' ORDER BY dateline ASC') or die(mysql_error()); This code won't run; what am I doing wrong?! Thanks in advance. - Mi Link to comment https://forums.phpfreaks.com/topic/80161-more-than-one-where-in-query/ Share on other sites More sharing options...
Rusnoff Posted December 4, 2007 Share Posted December 4, 2007 $gettopics = mysql_query('SELECT * FROM topics WHERE ((topics.systems LIKE "'.$system.'") OR (topics.topicid = '.$topic.')) ORDER BY dateline ASC') or die(mysql_error()); I have added the (( )). What error do you get? Or does this work already? Thats how i most of the time write it. Link to comment https://forums.phpfreaks.com/topic/80161-more-than-one-where-in-query/#findComment-406271 Share on other sites More sharing options...
kopytko Posted December 4, 2007 Share Posted December 4, 2007 Try this: <?php $gettopics = mysql_query("SELECT * FROM topics WHERE topisc.systems LIKE '".$system."' OR topics.topicid = ".$topic." ORDER BY dateline ASC") or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/80161-more-than-one-where-in-query/#findComment-406272 Share on other sites More sharing options...
Rusnoff Posted December 4, 2007 Share Posted December 4, 2007 Try this: <?php $gettopics = mysql_query("SELECT * FROM topics WHERE topisc.systems LIKE '".$system."' OR topics.topicid = ".$topic." ORDER BY dateline ASC") or die(mysql_error()); ?> you have there topisc... isn't right. btw, i assume you have only changed the PHP tag? I assume it was there already. Link to comment https://forums.phpfreaks.com/topic/80161-more-than-one-where-in-query/#findComment-406275 Share on other sites More sharing options...
revraz Posted December 4, 2007 Share Posted December 4, 2007 "SELECT * FROM topics WHERE systems LIKE '$id' OR topicid = '$topic' ORDER BY dateline ASC" Link to comment https://forums.phpfreaks.com/topic/80161-more-than-one-where-in-query/#findComment-406276 Share on other sites More sharing options...
kopytko Posted December 4, 2007 Share Posted December 4, 2007 Try this: <?php $gettopics = mysql_query("SELECT * FROM topics WHERE topisc.systems LIKE '".$system."' OR topics.topicid = ".$topic." ORDER BY dateline ASC") or die(mysql_error()); ?> you have there topisc... isn't right. btw, i assume you have only changed the PHP tag? I assume it was there already. Look closer. Hint: qoutes. Link to comment https://forums.phpfreaks.com/topic/80161-more-than-one-where-in-query/#findComment-406278 Share on other sites More sharing options...
Michan Posted December 4, 2007 Author Share Posted December 4, 2007 Guys, I need the wildcard to select from a field which contains data formatted like |1|2|3| Here's the error I'm getting: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY articlecomments_topics.dateline ASC' at line 1 Link to comment https://forums.phpfreaks.com/topic/80161-more-than-one-where-in-query/#findComment-406283 Share on other sites More sharing options...
pocobueno1388 Posted December 4, 2007 Share Posted December 4, 2007 Do this <?php $query = "SELECT * FROM topics WHERE topics.systems LIKE '%$system%' OR topics.topicid = '$topic' ORDER BY dateline ASC" $result = mysql_query($query)or die(mysql_error()."With Query:<br>$query"); ?> Link to comment https://forums.phpfreaks.com/topic/80161-more-than-one-where-in-query/#findComment-406284 Share on other sites More sharing options...
revraz Posted December 4, 2007 Share Posted December 4, 2007 Add % for the wildcard. We assume you knew that and included it in your variable. Guys, I need the wildcard to select from a field which contains data formatted like |1|2|3| Here's the error I'm getting: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY articlecomments_topics.dateline ASC' at line 1 Link to comment https://forums.phpfreaks.com/topic/80161-more-than-one-where-in-query/#findComment-406286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.