Powered by Bravenet Bravenet Blog

Friday, April 17th 2009

2:07 PM

PHP Geekiness: PHP Trick When Searching An Access Database


With PHP you can pass variables from a HTML form to a PHP script. You can also use that same variable to do searches on a MySQL or Access database. This would be handy for searching... say a Knowledge Base for example. ;) Look for PHP goodness in the next version of DoyleSoft Knowledge Base.

Here is how the form is layed out in HTML:

form name="form" action="search.php" method="get"
  input type="text" name="q" /
  input type="submit" name="Submit" value="Search" /
/form

I left out HTML brackets in this example.

Here is how the variable is declared in PHP:

 $var = @$_GET['q'] ;

And finally, here is how the SQL Select Statement should look:

$sql="SELECT * FROM KB where PROBLEM LIKE '%$var%' ORDER BY Problem";

Notice that the variable has percent signs around it to indicate anything relating to the variable should be included. In short, yeah, it's good stuff!
-Brandonbert

0 Comment(s).

There are no comments to this entry.

Post New Comment

 BraveJournal Member Non-Member
No Smilies More Smilies »
Please type the letters you see