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 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    search no results

    hello Again!!!
    & Happy new year to All

    i m trying to make a search page.
    the code is.....

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>
    <?php
    include("config.inc.php");


    if(isset(
    $_GET['search']))
    {
    $search $_GET['search'];
    }

    $keywords explode(" "$search);

    $query "SELECT photo_id,photo_filename,photo_caption,photo_category,Gerne,First,Last,elm1,photo_category1,date_submited,enddate FROM gallery_photos " .
    "WHERE First LIKE '%".$keywords['0']."%'";

    for (
    $i=1$i<count($keywords); $i++) {
    $query $query." OR First LIKE '%".$keywords[$i]."%'";
    }

    $result mysql_query($query) or die(mysql_error());
    ?>
    <center>
    <form method="GET" action="search1.php">
    <b>Search:</b> <input type="text" name="search" size="20" />
    <input type="submit" value="Search!" />
    </form>
    <table width="50%" style="border:1px solid #000000;">
    <?php
    while($row mysql_fetch_array($result))
    {
    echo 
    "<tr>";
    echo 
    "<td style='border-bottom: 1px solid #000000;'>";
    echo 
    "<b>".$row['photo_caption']."</b>";
    echo 
    "<p>".$row['First']."</p>";
    echo 
    "<p>".$row['Last']."</p>";
    echo 
    "<p>".$row['photo_filename']."</p>";
    echo 
    "<p>".$row['photo_category1']."</p>";
    echo 
    "<p>".$row['enddate']."</p>";
    echo 
    "<b>".$row['date_submited']."</b>";
    echo 
    "</td>";
    echo 
    "</tr>";
    }
    ?>
    </td>
    </tr>
    </table>
    <a href="HTMLinput.htm">Add new record to our DataBank.</a>
    </center>
    </body>
    </html>
    when i first load this page i m geting all the results of my table gallery_photos
    but when im using the search field i dont get any results or errors

    Can any1 Help me pls????

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try running print_r($keywords); after $keywords = explode(" ", $search); to see if the keywords are even being split properly. Also, are you sure the 'First' field is filled in on the database?
    "$question = ( to() ) ? be() : ~be();"

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Two things you might want to look at:

    Code:
    if(isset($_GET['search']))
    {
    $search = $_GET['search'];
    }
    if search is not set what happens?

    you should use something like
    Code:
    $search = $_GET['search'];
    if(empty($search)){
    echo "You did not search for anything!";
    }else{
    //your search results
    }

    Code:
    $query = "SELECT photo_id,photo_filename,photo_caption,photo_category,Gerne,First,Last,elm1,photo_category1,date_submited,enddate FROM gallery_photos " .
    "WHERE First LIKE '%".$keywords['0']."%'";
    
    for ($i=1; $i<count($keywords); $i++) {
    $query = $query." OR First LIKE '%".$keywords[$i]."%'";
    }
    I am not 100% positive, but I think that their maybe something wrong with your loop, or what was you are combining the two strings.
    Last edited by eksob; 01-03-2006 at 08:11 PM.

  • #4
    New Coder
    Join Date
    Nov 2005
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thnx

    thnx friends..
    i ll try to follow your recommendations

  • #5
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by NTGre
    thnx friends..
    i ll try to follow your recommendations
    If you are doing the query like that, you might as well just input the entire search result into the query, what you need to do to search individual results would be to loop the entire query over and over. This could be annoying however, it also could give you more absolute results.

    Though, MySQl has useful options to search, you might try to search with $search with something like the LIKE option in MySQL.

    I'm briefly looking at this, trying to fix my rifle, I'll come back when you reply and if it isn't already solved I'll try a solution based off what you want the script to do.

  • #6
    New Coder
    Join Date
    Dec 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Consider MySQL Fulltext option as well


  •  

    Posting Permissions

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