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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.