SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    filter multiple columns, SELECT

    I've been unable to find a way to filter by two col's in a mysql table. I assume this is possible

    SELECT *
    FROM BOT
    WHERE `pol` OR `polb` LIKE '%colname%' AND ptb <>o

    This is coming off a form menu using GET VARS

    How can this be done?



  2. #2
    SitePoint Evangelist nick0161's Avatar
    Join Date
    Oct 2004
    Location
    australia
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i do this

    PHP Code:

    $db 
    mysql_connect("localhost","root","password"); //connect to mysql
    mysql_select_db("dbname",$db);   // select database "login"
    $sql "SELECT * from table";    // select table
    $result mysql_query($sql$db) or die ("Invalid query");  //catch errors

    //loop through table
        
    while ($row mysql_fetch_array($result)){
            if ( 
    "$row[col1]== "$something"){   
                if ( 
    "$row[col2]== "$something2"){ 
    this allows me to check two columns, is this what you mean?

  3. #3
    SitePoint Member jjdoblados's Avatar
    Join Date
    Nov 2004
    Location
    PH
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried:

    Code:
    SELECT *
    FROM BOT
    WHERE (pol LIKE '%colname%'
    
    OR polb LIKE '%colname%') AND ptb <> 0;
    I'm sure there are other ways. HTH.

  4. #4
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks jjdoblados vbmenu_register("postmenu_1497589", true); works nicely.

    Thanks too nick0161, haven't tried with Dreamweaver, but it treats a little different.

    I started looking into splitting the SELECT into two parts & using UNION to bring it back together (don't know if this can be done without filtering by rowid)

  5. #5
    SitePoint Member jjdoblados's Avatar
    Join Date
    Nov 2004
    Location
    PH
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I started looking into splitting the SELECT into two parts & using UNION to bring it back together (don't know if this can be done without filtering by rowid)
    Hi! Maybe you can give us more details on what it is exactly that you want to accomplish, and maybe we can start with that.

  6. #6
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by datadriven
    I started looking into splitting the SELECT into two parts & using UNION to bring it back together
    Depends what you actually want to do.
    Just bear in mind that UNION is posibble with MySQL >= 4.x
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.


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
  •