note 16684 deleted from function.odbc-field-name by jimw

From: Date: Sat, 10 Nov 2001 23:31:52 +0000
Subject: note 16684 deleted from function.odbc-field-name by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20702@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..."; } ?>

« previous php.notes (#20702) next »