I am wanting to create a standard search box on a php site. How do I do a "search" for specific terms and such??
Help please

Thank you.

    Hi Landy.

    If you are searching a database, it is very easy. All ou have to do is make a box and give it a variable, say $string. Once that is done, make the PHP script that proccesses it. It should look something like this:

    $request="SELECT * FROM tablename WHERE something = '$string' OR somethingelse='$string'";
    

    Then, if doesn't find anything, do something like this:

    if (mysql_num_rows($result) == 0)
    {
    echo "Sorry...";
    }
    

    And if it does find something (continuation to the above script):

    else 
    { 
    while ($row = mysql_fetch_object ($result)) 
    {
        print "<tr>";
        print "<td>$ligne->coulumn1</td>";
        print "<td>$ligne->coulm2</td>";
        print "<td>$ligne->column3</td>";
        print "<td>$ligne->column4</td>";
        print "</tr>";
    }
    mysql_free_result ($result);
    

    That is very basic, but it should give you a start. Good luck.

      and, if you want to search within fields with a mysql query use a query like this:

      SELECT * FROM tablename WHERE something LIKE '$string'

      using = requires that the search string is EXACTALLY the same as the field in the database, LIKE means that the string appears somewhere in the field.

        Okay, I have the following code, and it looks like everything works when I do a Select * From Products, but when I do the "LIKE" statement, it says, "sorry...." and I put in exactly what is in the database............hmmmmm

        $sql = "SELECT * FROM products WHERE name LIKE '$searchString'" ;
        #WHERE name LIKE '$searchString'"
        $result = @($sql, $dbconn);
        if (!$sql) {
        echo( "<P>Unable to execute query at this time.</P>" );
        exit();

        							          }
        
        									if (mysql_num_rows($result) == 0)
        									{
        									echo "Sorry...";
        									}
        									else 
        									{ 
        									while ($row = mysql_fetch_array($result)) 
        									{
        
        
                       $name = $row['name'];
                       $image1 = $row['image1'];
                       $description = $row['description'];
                       $uniqueid = $row['uniqueid'];
                       $modnum = $row['modnum'];
                       $price = $row['price'];
        								 $prodid = $row['prodid'];
        								 echo ("<table>");
        								 echo ("<tr><td>$name</tr></td>");
        								 echo ("</table>");
        										}
        
        										}
          Write a Reply...