SELECT * from tablename where FIELD_3 = "search text"
will find exact matches

SELECT * from tablename where FIELD_3 LIKE "search text"
will find close matches

Using % as a wild card will broaden the search
SELECT * from tablename where FIELD_3 LIKE "search text%"
will find close matches where the search text could be at the begining of
the data 'ap%' will return rows with 'apple' or 'apartment', but not
'snapple', in the field

SELECT * from tablename where FIELD_3 LIKE "%search text%"
will find close matches where the search text could be anywhere in the  data
'%ap%' will return rows with 'a bowl of apples' in the field.

For the php using the best query from above on MySql

//connect to the server
$mysql_db_link = mysql_connect("domain", "username", "password");
//select database
mysql_select_db(database, $mysql_db_link ) ;

$query = 'query from above';
//run the query
$mysql_result = mysql_query($query, $mysql_db_link);

//output results
print ('Found the following values in the database <BR>')

//loop through returned results, printing each one
while($row = mysql_fetch_array($mysql_result))
{
print ($row["FIELD_3"].'<BR>');
}// end while


Peter

> -----Original Message-----
> From: Dave Carrera [mailto:[EMAIL PROTECTED]]
> Sent: 11 November 2001 06:38
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] How do i search my database...
>
>
> Hi All,
> I have a database with only three fields
>
> FIELD 1
> FIELD 2
> FIELD 3
>
> I want the user to input into FIELD 3, and then my script to go of to my
> database and see if it finds a match or something like the input
> and display
> it to the screen.
>
> Please help as i can't seem to get my brain around this....
>
> Thanks in Advance
>
>
> --
> 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]


-- 
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