jquery - Php to query sidebar -
i starting website , can query products in table display on page. in left sidebar displays color , price
color
yellow (3)
white (9)
tan (1)
red (3)
purple (1)
pink (7)
orange (1)
multi (1)
green (8)
brown (1)
blue (3)
black (3)
price
under $25 (4)
$25-$50 (4)
2/$40 (22)
2/$50 (10)
3/$33 (1)
so used count , group display this. want click on 1 of colors or 1 of prices , narrow products down. click on black want able query 3 black products
here php products in table
<?php $dynamiclist =""; $sql = mysql_query("select * test2 limit"); $productcount = mysql_num_rows($sql); if ($productcount > 0) { while($row = mysql_fetch_array($sql)){ $product_name = $row["product_name"]; $image_url = $row["image_url"]; $category = $row["category"]; $subcategory = $row["subcategory"]; $sub_subcategory = $row["sub_subcategory"]; $price = $row["price"]; $color = $row["color"]; $page_url = $row["page_url"]; $dynamiclist .= '<div id="products"> <table width="24%" height="339" border="0" align="left" cellpadding="0"> <tr> <td height="150" align="center" valign="bottom"><a href="'.$page_url.'" target="_blank"><img src="'.$image_url.'" hspace="5" vspace="10" width="140" height="210" /></a></td> </tr> <tr> <td height="90" align="center" valign="top"><p><a href="'.$page_url.'" target="_blank">'.$product_name.'<br /><b><font size="3"><font color="#ff0000">'.$price.'</font> </font></b></a></p></td> </tr> </table></div>'; } } else { $dynamiclist = "<b>there no items</b>"; } ?>
and php for color , price display on left sidebar want able link
<?php echo $sidebar_color =""; $sql = mysql_query("select *,count(color) test2 group color order color desc"); $productcount = mysql_num_rows($sql); if ($productcount > 0) { while($row = mysql_fetch_array($sql)){ $color = $row["color"]; $sidebar_color .= '<div id="sidebar"><p><font size="-2"><a href="index.php?'.$color.'">'.$color.' ('.$row["count(color)"].')</a> </font></p></div>'; } } ?> <?php echo $sidebar_price =""; $sql = mysql_query("select *,count(sidebar) test2 group price order price asc"); $productcount = mysql_num_rows($sql); if ($productcount > 0) { while($row = mysql_fetch_array($sql)){ $price = $row["price"]; $sidebar_price .= '<div id="price"><p><font size="-2"><a href="index.php?'.$price.'">'.$price.' ('.$row["count(price)"].')</a> </font></p></div>'; } } ?>
hi bryan comment. wasn't able work. kept coming error. code displayed on page
<div id="side" <ul> <p>_____________</p> <p><font size="3"><b>color</b></font></p> <font size="-2"><li><?php echo $sidebar_color; ?></li> </font></ul> <ul> <p>_____________</p> <p><font size="3"><b>price</b></font></p> <font size="-2"><li><?php echo $sidebar_price; ?></li> </font></ul> </div> </td> <td width="80%" valign="top"><p> <?php echo $dynamiclist; ?><br /> </p></td>
so when click on black again need display $dynamiclist products black.
i hope makes sense you. new @ this. appreciated.
replace line(same price)
<a href="index.php?'.$color.'">
with
<a href="index.php?color='.$color.(isset($_get['price'])?'&price='.$_get['price']: '').'">
then can use $_get['color'] , $_get['price'] set query display products ie...
$options = array(); (isset($_get['price']) ? $options[] = "price='".mysql_real_escape_string($_get['price'])."'" : '' ); (isset($_get['color']) ? $options[] = "color='" mysql_real_escape_string($_get['color'])."'" : '' ); $query = "select * `table` ".implode(' , ', $options);
also fyi mysql functions should replaced mysqli.
Comments
Post a Comment