Results 1 to 6 of 6

Thread: [RESOLVED] Easy SQL problem

  1. #1

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Resolved [RESOLVED] Easy SQL problem

    im trying to search a table based on fname and sname fields

    PHP Code:
    $sql "SELECT * FROM members WHERE fname, sname LIKE '%$search%'"
    the above gives me a mysql error. but the following works when I search just the fname field

    PHP Code:
    $sql "SELECT * FROM members WHERE fname LIKE '%$search%'"
    anyone know the SQL syntax for searching more than one field?
    Last edited by the182guy; Mar 23rd, 2006 at 09:49 AM.
    Chris

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Easy SQL problem

    Well, in your example. both lines are the same.... probably related to copy/pasting...

    What I think you want is this:

    Code:
     $sql = "SELECT * FROM members WHERE fname '%$search%' OR sname LIKE '%$search%'";
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Easy SQL problem

    PHP Code:
    $sql "SELECT * FROM members WHERE fname '%$search%' OR sname LIKE '%$search%'"
    errors ive tried playing around with it
    Chris

  4. #4

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Easy SQL problem

    i know it is the SQL query that is causing the error because

    SELECT * FROM members

    works with no error, only when i try to search two fields
    Chris

  5. #5

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Easy SQL problem

    ok got it working now

    PHP Code:
    $sql "SELECT * FROM members WHERE fname LIKE '%$search%' OR sname LIKE '%$search%'"
    Chris

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Easy SQL problem

    hehehe.... sorry about that... I felt off the LIKE on the first one didn't I?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

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



Click Here to Expand Forum to Full Width