note 16684 added to function.odbc-field-name
| From: | jp58782 at u dot washington dot edu | Date: | Thu, 08 Nov 2001 21:29:04 +0000 |
| Subject: | note 16684 added to function.odbc-field-name | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-20619@lists.php.net to get a copy of this message | ||
You can add to that code to make a simple keyword search for you table. I use this all the time but
have never seen it posted anywhere.. The '%' acts as a wildcard in SQL... Just make a
form that calls this page as the action and has one input named key.
<?
if ($key){
$connectionstring = odbc_connect("urdb","","");
$searchquery="SELECT * FROM table WHERE ";
$query = "SELECT * FROM table";
$result = odbc_exec($connectionstring, $query);
$i = 0;
$fCount = odbc_num_fields($result);
while ($i < $fCount-1)
{
$i++;
$fName = odbc_field_name($result, $i);
$searchquery=$searchquery . "[" . $fName . "] LIKE '%" . $key .
"%' OR ";
}
// Last entry has no 'or'
$fName = odbc_field_name($result, $i);
$searchquery=$searchquery . $fName . " LIKE '%" . $key . "%'";
//echo $searchquery;
//execute query
$queryexe = odbc_do($connectionstring, $searchquery);
//output results to standard output
odbc_result_all($queryexe, "BORDER=1");
//diconnect from database
odbc_close($connectionstring);
}
else {
print "you left too much blank..., go back and try again please...";
}
?>
--
http://www.php.net/manual/en/function.odbc-field-name.php
http://master.php.net/manage/user-notes.php?action=edit+16684
http://master.php.net/manage/user-notes.php?action=delete+16684
http://master.php.net/manage/user-notes.php?action=reject+16684