php - How to display more than one result from search -



php - How to display more than one result from search -

i trying display results search whatever still shows me 1 , want create link each result product. suggestions? thanks

my search_engine.php code

include("storescripts/init.php"); //connect db $button = $_get ['submit']; $search = $_get ['search']; if ($search === 'search products'){ echo "please come in value!"; } else { if(strlen($search)<=1) echo "search term short"; else { echo "<br />you searched <b>$search</b> <hr size='1'></br>"; $search_exploded = explode (" ", $search); foreach($search_exploded $search_each) { if($search_each) $construct .="product_name '%$search_each%' or brand '%$search_each%' or category '%$search_each%'"; } $constructs ="select * products $construct limit 100 "; $run = mysql_query($constructs); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "sorry, there no matching result <b>$search</b>.<br /> please check spelling"; else { echo "$foundnum results found !<p>"; $getquery = mysql_query("select * products $construct limit 100 "); while($runrows = mysql_fetch_assoc($getquery)) { $product_name = $runrows ['product_name']; $brand = $runrows ['brand']; $category = $runrows ['category']; } echo " <a href=#>$product_name</a> &nbsp; $brand &nbsp; $category<p> "; } }

and form code

<form action="product_search.php" method="get"> <input type="text" onclick="this.value='';" value="search products" name="search" size="18" maxlength="60"/> <input type="submit" style=" background-color:orange; font-size:17px; border-radius:10px;" value="go!" name="submit"/> </form>

you need alter following

while($runrows = mysql_fetch_assoc($getquery)) { $product_name = $runrows ['product_name']; $brand = $runrows ['brand']; $category = $runrows ['category']; } echo " <a href=#>$product_name</a> &nbsp; $brand &nbsp; $category<p> ";

to

while($runrows = mysql_fetch_assoc($getquery)) { $product_name = $runrows ['product_name']; $brand = $runrows ['brand']; $category = $runrows ['category']; echo " <a href=#>$product_name</a> &nbsp; $brand &nbsp; $category<p> "; }

you displaying info outside loop , hence after loop finished lastly info shown.

php html mysql

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -