#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    40
    Rep Power
    0

    Php mysql problum!!!


    PHP Code:
    $searchKey="Tom";
    $query "SELECT * FROM video123 WHERE yt_title like '%$searchKey%' LIMIT 0, 10 " 
    it returns only one row which has Tom in yt_title .

    PHP Code:
    [
    {
    "yt_title":"Fashion House 15 12 2013 Full Episode","showid":"1","seasinId":"2","thumb_medium":"https:\/\/i1.ytimg.com\/vi\/T3i7I3oZ988\/mqdefault.jpg "},

    {
    "yt_title":"Tom","showid":"1","seasinId":"2","thumb_medium":"https:\/\/i1.ytimg.com\/vi\/MEWGIYljtLo\/mqdefault.jpg "},

    {
    "yt_title":"Fashion Choreographer Dalu with models Dimple & Ishara","showid":"1","seasinId":"2","thumb_medium":"https:\/\/i1.ytimg.com\/vi\/nfzaTAhyjiI\/mqdefault.jpg "},

    {
    "yt_title":"Fashion House -  Latest men's wear collections at Mufti","showid":"1","seasinId":"2","thumb_medium":"https:\/\/i1.ytimg.com\/vi\/aJo8kChx3vg\/mqdefault.jpg "},

    {
    "yt_title":"White & bright facial","showid":"1","seasinId":"2","thumb_medium":"https:\/\/i1.ytimg.com\/vi\/P9EHVNNg2PM\/mqdefault.jpg "}] 
    and if i change my query to -
    PHP Code:
    $query "SELECT * FROM video123 WHERE yt_title ='$searchKey' " 
    it returns Null
    Last edited by sunny1234567890; January 13th, 2014 at 05:59 AM. Reason: sorry my mistake .....
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,114
    Rep Power
    9398
    1. The first query you posted is invalid. It did not return anything.
    2. If all you did was change the "like %$searchKey%" to "= '$searchKey'" then the query would work and return the one row.

    So either way your code doesn't match your description.
  4. #3
  5. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    PHP Code:
    $query "SELECT * FROM video123 WHERE yt_title like '%$searchKey%' LIMIT 0, 10 " 
    Corrected faulty SQL (was a missing ' in front of the first %)
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    40
    Rep Power
    0

    hmmm


    I tried this also returns null
    $searchKey
    $query = "SELECT * FROM video123 WHERE yt_title ='$searchKey' " ;

    and i am implimenting autocomplete , so how do i query db for autocomplete???
  8. #5
  9. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    Sunny
    The $query above has the correct syntax so if it's not returning any results, that may well be the case ... are there any titles that match the string within $searchKey ?

    Have you got access to PHPMyAdmin or MySQL Workbench so you can echo the $query to the screen, copy and paste it into the Workbench and see if there are any results.

    Did you even try the corrected SQL that I suggested above?
    I'd get that right before you move onto autocomplete using Ajax (although, that is just a presumption as you've not said anything about what you even mean by autocomplete)
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    40
    Rep Power
    0
    autocomplete means live search
  12. #7
  13. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    yes, I figured as much.
    You must first get your SQL working before you can move onto the 'live search' auto complete stuff.

    Are you making any progress with that based on the help I've provided you above?
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    40
    Rep Power
    0

    thanks


    Live search working fine using this query
    PHP Code:
    $query "SELECT * FROM video123 WHERE yt_title like '".$searchKey."%' LIMIT 0, 10 " 

    But
    when i use this query to search
    PHP Code:
    $query "SELECT * FROM video WHERE yt_title =$skey
    it returns null
  16. #9
  17. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    Wrap $skey in single quotes
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    40
    Rep Power
    0

    :(


    these both are also not working.

    PHP Code:
    $query 'SELECT * FROM video123 WHERE yt_title ="'.$a.'"' ;
    $query ="SELECT * FROM video123 WHERE yt_title ='$a.'"

    tried this also
    PHP Code:
    $a=$mysqli->real_escape_string($skey);
    $query 'SELECT * FROM video123 WHERE yt_title ="'.$a.'"' ;
    $query ="SELECT * FROM video123 WHERE yt_title ='$a.'"
  20. #11
  21. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    There's no real reason why the first one should't work, the syntax is correct for a simple SELECT statement.

    The 2nd one probably doesn't work because you have a period ( . ) after the $a within the WHERE clause.

    Have you actually tried to echo $query; to see what query is actually being sent to your SQL server?
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    When it equals something, it must match identically, so make sure it isn't even missing a space or anything. As far as things returning no more than 1 row, what does your full SQL look like?
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him

IMN logo majestic logo threadwatch logo seochat tools logo