Jump to content

More than one WHERE in query?


Michan

Recommended Posts

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

 

 

$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.

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.

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.

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.