SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: OR problem

  1. #1
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OR problem

    I'm using the following query:
    Code:
        $sql = mysql_query("SELECT fi.fname, fi.comment, fi.ftime, fo.foname
                            FROM files as fi, folders as fo
                            WHERE fi.ffolder = foid AND fi.fname LIKE '%".$searchstring."%'
                            #OR fi.comment LIKE '%".$searchstring."%'
                            ORDER BY fo.foname, fi.fname") or die(mysql_error());
    The line that is commented out is causing me loads of problems! What I need to do is select files where fi.ffolder = foid and where either the filename (fi.fname) or comment (fi.comment) is like the search string

    Any thoughts?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    Code:
    $sql = mysql_query("SELECT fi.fname, fi.comment, fi.ftime, fo.foname
                        FROM files as fi, folders as fo
                        WHERE fi.ffolder = foid AND (fi.fname LIKE '%".$searchstring."%'
                        OR fi.comment LIKE '%".$searchstring."%')
                        ORDER BY fo.foname, fi.fname") or die(mysql_error());
    precedence thing with AND/OR. parentheses should fix that.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Matt I could kiss you!

    The stupid thing is I actually thought about trying that and then completely forgot :slaps head:

    Thank you

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)




    great.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


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
  •