RE: [PHP-DB] How do i search my database...
| From: | Peter Lovatt | Date: | Sun, 11 Nov 2001 10:03:11 +0000 |
| Subject: | RE: [PHP-DB] How do i search my database... | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-14229@lists.php.net to get a copy of this message | ||
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:dave@davecarrera.com]
> Sent: 11 November 2001 06:38
> To: php-db@lists.php.net
> 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: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net