> if ($row = mysql_fetch_array($result)) {
> /* Change all instances of db_table to match your db table structure */
> do {
>   PRINT "Your search results: <br><br>";
>   PRINT "<b>db_table:     </b> ";
>   print $row["db_table"];
>   print ("<br>");
>   .....
>   .....
>   PRINT "<b>db_table:     </b> ";
>   print $row["db_table"];
>   print ("<br>");
>   print ("<hr>");
> } while($row = mysql_fetch_array($result));
> } else {print "Sorry, no records were found!";}

You can shorten this considerably using a while loop (see comments for

// Get the results
$result = mysql_query($query);

// If a result was returned, you have a properly formed query
if ($result) {
    // You can get a result and no rows.  Check for rows!
    if (mysql_num_rows() > 0) {

        // As long as there are rows in the result resource, keep printing
        while ($row = mysql_fetch_array($result)) {
            print "<b>db table:</b> " . $row["db_table"] . "<br>";
        print "<hr>";

    // Good query, good result, but no rows returned.  No matches in the DB!
    else { print "Sorrym no records were found!"; }

// If $result evaluates to FALSE then the problem is usually in your SQL
else { print "An error has occurred!  Check your SQL syntax!"; }

Using this format allows you to print only what is necessary.  At the same
time, if you had more results than you had spaces to print them, your
results would have been truncated.

If you want to be able to search multiple columns in your DB, you can for
your query as:

SELECT * FROM table WHERE (column1 LIKE '%$var%') || (column2 LIKE '%$var%')
[ continued for as many fields as necessary ]

Mike Frazer
Inverted Mind

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to