SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2001
    Location
    Holland
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Another (quite) newbie question

    Hi,

    I need to make a WHERE name LIKE %textvalue% query in my database. First i tried this:

    PHP Code:
    if ($Search == Search
    $eps mysql_query("SELECT naam, id, date FROM apple WHERE naam LIKE \"%$sid\""); } 
    wich resulted in a my_sql error, i thought this was either a quotation problem or the $sid wasn't in the mysql string, that last one was easy to find out, i removed the mysql_query function and echo("$eps"); wich stated the query correctly.

    Then I reconstructed with echo's and stuff to make sure the quotes wasn't a problem wich alse came out negative..

    Can someone help me out here?, it's probebly a minor mistake.


    (Just in case, Search == Search chks if the search button is pressed and $sid is a value you enter in a form)

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Try this:

    PHP Code:
    if ($Search == "Search"
    $eps mysql_query("SELECT naam, id, date FROM apple WHERE naam LIKE '%$sid'"); } 

  3. #3
    SitePoint Member
    Join Date
    May 2001
    Location
    Holland
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah yes, I forgot to some quotes here and then,. but the code U stated didn't work either

    I think I'm making a major error here, let me first paste some code over here

    PHP Code:
    if ($Search == "Search") {
    $sql "SELECT naam FROM appel";
    $eps mysql_query("$sql"); 
    This wil put the data of the column naam from appel into $eps, now I can get put this info into paragraphs (or tables)
    PHP Code:
    while ($row mysql_fetch_array($eps) ) {
    $naam=$row["naam"]; echo("<p>"$naam "</p>"); 
    And close the functions
    PHP Code:
    } } 
    Now i wish to search the database for specific data, and I've searched the mysql reference to make that happen

    All i need to do is add a WHERE naam LIKE %$sid% line in the mysql console wich works perfectly, now adding it into my php code.. i chanched the $sql line into:

    PHP Code:
    $sql "SELECT naam FROM appel" 
    "WHERE naam LIKE %$sid%"
    wich gives me an undefined call error,.. what's wrong with my aproach?, are there alternatives?

  4. #4
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You must put single quotes around %$sid% so '%$sid%'.
    Also, make sure that sid actually exists.

  5. #5
    SitePoint Zealot oodie's Avatar
    Join Date
    Jul 2000
    Location
    Misty Mountain
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Joop
    PHP Code:
    $sql "SELECT naam FROM appel" 
    "WHERE naam LIKE %$sid%"
    You forget to put a space here between appel and WHERE. Also like petesmc said, put space around %$sid%
    PHP Code:
    $sql "SELECT naam FROM appel" 
    " WHERE naam LIKE '%$sid%'"
    If the above fails, try to put $sid outside the quote like this.
    PHP Code:
    $sql "SELECT naam FROM appel" 
    " WHERE naam LIKE '%"$sid"%'"


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
  •