Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts

    php/mysql search page

    i this script now it is supposed to be a search
    PHP Code:
    <?php
    $i 
    0;
    $readin '+'.$_GET['Search'];
    $words explode("+"$readin);
    $max count($words) - 1;
    while(
    $i != $max)
    {
    $sql "SELECT * FROM `pages` where `keywords` LIKE '%".$words[$i]."%' LIMIT 0,10";
    $query mysql_query($sql$con);
     while(
    $row mysql_fetch_array($query))
     {
     echo
    '   <table width="409" border="0">
        <tr>
          <td><a style="color: #4A912B;" href="http://www.brook-babes.org.uk/'
    .$row['link'].'">BrookBabes: '.$row['title'].'</a></td>
        </tr>
        <tr>
         <td>'
    .$row['Content'].'</td>
        </tr>
        <tr>
          <td><h6>http://www.brook-babes.org.uk/'
    .$row['link'].'</h6></td>
        </tr>
      </table>'
    ;
     }
    $i++;
    }
    $row mysql_fetch_array($query);
    if(
    $row['id'] > 10)echo 'Not found what you were looking for <br> try refining your search';
    ?>
    but for some reason this outputs all it can from my DB even with goboldy gook in there but if i change this
    PHP Code:
    $readin '+'.$_GET['Search']; 
    to
    PHP Code:
    $readin ''.$_GET['Search']; 
    i dont get any results yet of the tutorials i have read it sould work can any one help please

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Use print_r on your array and you'll see why. You're array most likely contains an empty string. When that string is concatenated with &#37;'s on either side, you're then matching for '%%' - which is going to match everything in your database. I only know this because I fixed the very same problem in one of my scripts recently.
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    ok thanks for that i will have a look

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    Thanks i got it working
    PHP Code:
    $i 0;
    $readin ''.$_GET['Search'];
    $words explode("+"$readin);
    $max count($words);
    while(
    $i != $max)
    {
    $sql "SELECT * FROM `pages` where `keywords` LIKE '%".$words[$i]."%' LIMIT 0,10";
    $query mysql_query($sql$con);
     while(
    $row mysql_fetch_array($query))
     {
     echo
    '   <table width="409" border="0">
        <tr>
          <td><a style="color: #4A912B;" href="http://www.brook-babes.org.uk/'
    .$row['link'].'">BrookBabes: '.$row['title'].'</a></td>
        </tr>
        <tr>
         <td>'
    .$row['Content'].'</td>
        </tr>
        <tr>
          <td><h6>http://www.brook-babes.org.uk/'
    .$row['link'].'</h6></td>
        </tr>
      </table>'
    ;
     }
    $i++;
    }
    $row mysql_fetch_array($query);
    if(isset(
    $row['id']))echo 'Sorry we could not find a page with your keywords in it';
    if(
    $row['id'] > 10)echo 'Not found what you were looking for <br> try refining your search';
    ?> 

  • #5
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    have a look at it working
    http://www.brook-babes.org.uk/


  •  

    Posting Permissions

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