note 29668 added to function.mysql-field-name

From: Date: Fri, 21 Feb 2003 00:07:24 +0000
Subject: note 29668 added to function.mysql-field-name
Groups: php.notes 
Request: Send a blank email to php-notes+get-44278@lists.php.net to get a copy of this message
<? /* By simply calling the searchtable() function with these variables it will serach the desired database and procude a table for each field that there is a match. */ function searchtable($host,$user,$pass,$database,$tablename,$userquery) { $link = mysql_connect($host, $user, $pass) or die("Could not connect: " . mysql_error()); $db = mysql_select_db($database, $link) or die(mysql_error()); $fields = mysql_list_fields($database, $tablename, $link); $cols = mysql_num_fields($fields); for ($i = 1; $i < $cols; $i++) { $allfields[] = mysql_field_name($fields, $i); } foreach ($allfields as $myfield) { $result = mysql_query("SELECT * FROM $tablename WHERE $myfield like '%$userquery%' "); if (mysql_num_rows($result) > 0){ echo "<h3>search <i>$database</i> for <i>$userquery</i>, found match(es) in <i>$myfield</i>: </h3>\n"; echo "<table border=1 align=\"center\">\n\t<tr>\n"; for ($i = 1; $i < $cols; $i++) { echo "\t\t<th"; if ($myfield == mysql_field_name($fields, $i)){ echo " bgcolor=\"orange\"> "; } else { echo ">"; } echo mysql_field_name($fields, $i) . "</th>\n"; } echo "\t</tr>\n"; $myrow = mysql_fetch_array($result); do { echo "\t<tr>\n"; for ($i = 1; $i < $cols; $i++){ echo "\t\t<td> $myrow[$i] &nbsp;</td>\n"; } echo "\t</tr>\n"; } while ($myrow = mysql_fetch_array($result)); echo "</table>\n"; } } } searchtable($host,$user,$pass,$database,$tablename,$userquery); ?> -- http://www.php.net/manual/en/function.mysql-field-name.php http://master.php.net/manage/user-notes.php?action=edit+29668 http://master.php.net/manage/user-notes.php?action=delete+29668 http://master.php.net/manage/user-notes.php?action=reject+29668

« previous php.notes (#44278) next »