php - Get MySQL data WHERE column equals HTML link when clicked -
don't quite know how work one, appreciated. i'm trying display products match column of link have been clicked. have succeeded in doing search function when click button (search). i'm trying implement similar method when link pressed.
$sql = "select * products "; if(isset($_post['submit'])){ if(empty($_post['search'])){ $error = true; }else{ $searchq = mysql_real_escape_string($_post['search']); $searchq = preg_replace("#[^0-9a-z]#i","",$searchq); $sql .= "where type '%$searchq%' or name '%$searchq%'"; } } $query = mysql_query($sql) or die(mysql_error());
the links this, when user has clicked link, displays data according name="" in link matches column type in table products.
<ul> <li name="books" class="menu-781"><a href="#">books</a></li> <li name="perfume" class="menu-780"><a href="#">perfume</a></li> <li name="gifts" class="menu-789"><a href="#">gifts</a></li> <li name="stationery" class="menu-778 last""><a href="#">stationery</a></li> </ul>
thanks in advance.
try code
<ul> <li name="books" class="menu-781"><a href="search.php?q=books">books</a></li> <li name="perfume" class="menu-780"><a href="search.php?q=perfume">perfume</a></li> <li name="gifts" class="menu-789"><a href="search.php?q=gifts">gifts</a></li> <li name="stationery" class="menu-778 last""><a href="search.php?q=stationery">stationery</a></li> </ul>
and in php
$sql = "select * products "; if(isset($_get['q'])){ if(empty($_get['q'])){ $error = true; }else{ $searchq = mysql_real_escape_string($_get['q']); $searchq = preg_replace("#[^0-9a-z]#i","",$searchq); $sql .= "where type '%$searchq%' or name '%$searchq%'"; } } $query = mysql_query($sql) or die(mysql_error());
Comments
Post a Comment