SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: multiple WHERE

  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got the SELECT thing down pact
    and the WHERE thing...

    How can I select things from a database depending if they have a particular value in any of three chosen collums.

    for exsample, lets say im looking for the name ""bob"
    I have three collums that must be searched name name1 name2 and name3

  2. #2
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe you would do something like:
    WHERE $name1 == "bob" OR $name2 == "bob" OR $name3 == "bob"

    This also works with AND
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  3. #3
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dosent seem to work
    this is what I got

    $result =mysql_query("SELECT * FROM list WHERE buscat1='$category' OR buscat3='$category'",$db)
    or die ("oh oh');

    I dont get an error, but it isnt picking anything up from buscat3

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    RKuhle gave you improper syntax. In sql the equality operator is "=" not "==" like in php.

    You seem to have gotten that sorted out ,though. Your syntax looks fine now.

    Your problem is with $db. Once you select the db, you don't use that variable again. The variable you use is $connection. Here is the proper syntax:
    Code:
    $connection=mysql_connect("localhost", "", "")
    or die("Couldn't connect to server.");
    $db=mysql_select_db("test_db", $connection)
    or die("Couldn't select database.");
    $sql="SELECT * ......;
    $sql_result=mysql_query($sql, $connection);
    $row=mysql_fetch_array($sql_result);
    Last edited by 7stud; May 16, 2001 at 19:41.

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Also your quotes on "oh oh" aren't of matching types.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •