SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My search in mysql includes only first word in textbox

    I have a php page where i hae a textbox named txtsearch that searches in mysql db based on keywords given. The problem is that it searches only for the first word in the textbox e.g i input fashion design, it will search only for fashion.

    My sql query and php code is like this:

    PHP Code:
    $colname_rsfindwebsitesearch "-1";
    if (isset(
    $_GET['txtsearch']) && !empty($_GET['txtsearch'])) {
      
    $colname_rsfindwebsitesearch = (get_magic_quotes_gpc()) ? $_GET['txtsearch'] : addslashes($_GET['txtsearch']);
    }

    "SELECT * FROM tbllinkscyprus WHERE (Keywords LIKE '%%%s%%' OR Title LIKE  '%%%s%%') OR URL LIKE  '%%%s%%' ORDER BY URL ASC"$colname_rsfindwebsitesearch,$colname_rsfindwebsitesearch,$colname_rsfindwebsitesearch); 
    Why is this happening?

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Are you sure it searches for the first word only? It seems to me that you expect it to search for each word separately while it searches for the phrase.
    Saul

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, because if i run a search using fashion design, it finds all the strings containing fashion and not design.

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    always check the value of your variables to make sure they are what you think they are.
    var_dump($_GET['txtsearch']);

    it also looks like your last variable in your code got broken apart.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried var_dump($_GET['txtsearch']); and i get the whole keyword string OK. I don't know why its looking only for the first word. I am desperate, please help.


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
  •