I have a site that displays the product information its name, id, price, quantity etc. Now I have displayed it in a way of using $_GET variable.
Like for example if I want to click the product page then the link would be
http://localhost/InventorySystem/Employee/Tools/?Item=ProductList
I don't have to make another php page for that all I need is a get method and it will display the product information.
Now my problem is, how to I implement a search function with it? Is there a way for me to create a search function like
?Item=ProductList&Search=SearchTerm
I'm having a hard time understanding how to do it. Any advice?
basically add another variable in your query string, like you just showed in your example: ?Item=ProductList&Search=SearchTerm
. and just do $_GET['Search']
to get the value, pass it to your mysql and implement a filter using the WHERE
clause compounded with LIKE
like so:
$searchkey = $_GET['Search'];
$result = mysql_query("SELECT * FROM table WHERE column LIKE '%".$searchkey."%'");
This will return results containing the term you passed in $searchkey
, e.g. if $searchkey = "ball"
then volleyball, basketball, baller, basketballvolley
are all valid matches.
EDIT:
Your html form should look something like this to be able to pass your required params in your query string:
<form method="GET">
<input type="hidden" name="Item" value="ProductList" />
Search: <input type="text" name="Search" />
<input type="submit" value="submit" />
</form>