[SIZE=2]Needed functions: [/SIZE]
[SIZE=2]mysql_connect() (in this example it's presupposed that a connection to your database already exists) [/SIZE]
[SIZE=2]explode() [/SIZE]
[SIZE=2]array() [/SIZE]
[SIZE=2]foreach() [/SIZE]
[SIZE=2]implode() [/SIZE]
[SIZE=2]mysql_query() [/SIZE]
[SIZE=2]mysql_error() [/SIZE]
[SIZE=2]php: [/SIZE]
[SIZE=2]$keywords = 'searching in a mysql database'; [/SIZE]
[SIZE=2]You could also write a form where the keywords could be entered. [/SIZE]
[SIZE=2]php: [/SIZE]
[SIZE=2]$association = 'AND'; [/SIZE]
[SIZE=2]Search mode AND or OR, can also be defined e.g. by RADIO-buttons. [/SIZE]
[SIZE=2]php: [/SIZE]
[SIZE=2]$keywords = explode(" ",$keywords); [/SIZE]
[SIZE=2]We must participate the keywords because we want later create a mysql query with them. [/SIZE]
[SIZE=2]php: [/SIZE]
[SIZE=2]$query = array(); [/SIZE]
[SIZE=2]foreach($keywords as $keyword) { [/SIZE]
[SIZE=2]$query[] = "( `name_of_first_field` LIKE '%".$keyword."%' [/SIZE]
[SIZE=2]OR `name_of_second_field` LIKE '%".$keyword."%' [/SIZE]
[SIZE=2]OR `name_of_third_field` LIKE '%".$keyword."%' [/SIZE]
[SIZE=2]OR `and_so_on` LIKE '%".$keyword."%') [/SIZE]
[SIZE=2]"; [/SIZE]
[SIZE=2]} [/SIZE]
[SIZE=2]Every keyword must be changed that we can use it in a mysql query. The %-symbol is a substitute symbol for the possible other text in the data row. [/SIZE]
[SIZE=2]php: [/SIZE]
[SIZE=2]$query = implode("\n ".$association." ",$query); [/SIZE]
[SIZE=2]Now we have to put the keywords together again by using the AND or the OR-association. [/SIZE]
[SIZE=2]php: [/SIZE]
[SIZE=2]$sql = " [/SIZE]
[SIZE=2]SELECT * [/SIZE]
[SIZE=2]FROM `name_of_table` [/SIZE]
[SIZE=2]WHERE ".$query." [/SIZE]
[SIZE=2];" [/SIZE]
[SIZE=2]$res = mysql_query($sql); [/SIZE]
[SIZE=2]if (!$res) { [/SIZE]
[SIZE=2]/** [/SIZE]
[SIZE=2]* This lines print the SQL statement in a viewable form. [/SIZE]
[SIZE=2]*/ [/SIZE]
[SIZE=2]print '<pre>'; [/SIZE]
[SIZE=2]print $sql; [/SIZE]
[SIZE=2]print '</pre>'; [/SIZE]
[SIZE=2]/** [/SIZE]
[SIZE=2]* E_USER_ERROR will exit the script. [/SIZE]
[SIZE=2]* E_USER_NOTICE and E_USER_WARNING won't stop the script. [/SIZE]
[SIZE=2]*/ [/SIZE]
[SIZE=2]trigger_error('Database query failed: '.mysql_error(), E_USER_ERROR); [/SIZE]
[SIZE=2]} else { [/SIZE]
[SIZE=2]/** [/SIZE]
[SIZE=2]* Add here the routines to print the results. [/SIZE]
[SIZE=2]*/ [/SIZE]
[SIZE=2]} [/SIZE]
[SIZE=2]...and at last, of course, we'll send the mysql - query and you could print the results as usual with mysql_fetch_object() or mysql_fetch_array()... [/SIZE]
[SIZE=2]Here's the whole script: [/SIZE]
[SIZE=2]php: [/SIZE]
[SIZE=2]$keywords = 'searching in a mysql database'; [/SIZE]
[SIZE=2]$association = 'AND'; [/SIZE]
[SIZE=2]$keywords = explode(" ",$keywords); [/SIZE]
[SIZE=2]$query = array(); [/SIZE]
[SIZE=2]foreach($keywords as $keyword) { [/SIZE]
[SIZE=2]$query[] = "( `name_of_first_field` LIKE '%".$keyword."%' [/SIZE]
[SIZE=2]OR `name_of_second_field` LIKE '%".$keyword."%' [/SIZE]
[SIZE=2]OR `name_of_third_field` LIKE '%".$keyword."%' [/SIZE]
[SIZE=2]OR `and_so_on` LIKE '%".$keyword."%') [/SIZE]
[SIZE=2]"; [/SIZE]
[SIZE=2]} [/SIZE]
[SIZE=2]$query = implode("\n ".$association." ",$query); [/SIZE]
[SIZE=2]$sql = " [/SIZE]
[SIZE=2]SELECT * [/SIZE]
[SIZE=2]FROM `name_of_table` [/SIZE]
[SIZE=2]WHERE ".$query." [/SIZE]
[SIZE=2];" [/SIZE]
[SIZE=2]$res = mysql_query($sql); [/SIZE]
[SIZE=2]if (!$res) { [/SIZE]
[SIZE=2]/** [/SIZE]
[SIZE=2]* This lines print the SQL statement in a viewable form. [/SIZE]
[SIZE=2]*/ [/SIZE]
[SIZE=2]print '<pre>'; [/SIZE]
[SIZE=2]print $sql; [/SIZE]
[SIZE=2]print '</pre>'; [/SIZE]
[SIZE=2]/** [/SIZE]
[SIZE=2]* E_USER_ERROR will stop the script. [/SIZE]
[SIZE=2]* E_USER_NOTICE und E_USER_WARNING won't stop the script. [/SIZE]
[SIZE=2]*/ [/SIZE]
[SIZE=2]trigger_error('Database query failed: '.mysql_error(), E_USER_ERROR); [/SIZE]
[SIZE=2]} else { [/SIZE]
[SIZE=2]/** [/SIZE]
[SIZE=2]* Add here the routines to print the results. [/SIZE]
[SIZE=2]*/ [/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]for more info visit
www.mysql.com/[/SIZE]
[SIZE=2]regards[/SIZE]
[SIZE=2]frih!![/SIZE]