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 Quote Link to comment 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. Quote Link to comment 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()); ?> Quote Link to comment 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. Quote Link to comment 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" Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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"); ?> Quote Link to comment 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 Quote Link to comment 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.