2014-12-04 3 views
0

Хотите, чтобы отсортировать по цене по cat_id при нажатии на продукт из выпадающего списка продукта будет Открыть в результатах на странице с результатами поиска по результату.php при нажатии на ссылку вверх и вниз пока нет ни одного продукта в базе данных .при нажатии по цене от высокой к низкой цене следует изменить

function.php

function getcategoryPro(){ 
if(isset($_GET['category'])){ 

$cat_id = $_GET['category']; 

// SQL query to interact with info from our database 

$get_category_pro = "SELECT * FROM products WHERE cat_id =$cat_id"; 
if (isset($_GET['sortby'])) { 
$sortby = $_GET['sortby']; 
// SQL query to interact with info from our database 
if ($sortby == 'pricehilo') { 
$get_category_pro = "SELECT * FROM products WHERE cat_id =$cat_id ORDER BY price DESC"; 
} 
elseif ($sortby == 'pricelohi') { 
$get_category_pro ="SELECT * FROM products WHERE cat_id =$cat_id ORDER BY price ASC"; 
    } 

} 
$run_category_pro= mysql_query($get_category_pro); 


    $count = mysql_num_rows($run_category_pro); 

if($count==0){ 
    echo"<h2>no Products found in this category!"; 
      } 

    $dynamicList = '<table border="0" cellpadding="2">'; 
while($row_products = mysql_fetch_array($run_category_pro)){ 

    $id = $row_products["id"]; 
    $product_name = $row_products["product_name"]; 
    $price=$row_products["price"]; 
    $date_added = strftime("%b %d, %Y",strtotime($row_products['date_added'])); 



    if ($i % 9 == 0) { // if $i is divisible by our target number (in this case "3") 
    $dynamicList .= 
    '<tr><td><img style="padding:10px;/><a href="product.php?id=' . $id . '"><img 
    style="border: #000033 1px solid;" src="inventory_images/' . $id . '.jpg" 
    width="200" height="225" alt="' . $product_name . '"/><br/> 
     <width="150" align="left" valign="top" scope="col">' . $product_name . '<br/> 
     Rs.&nbsp;' . $price . '<br/> 
     <a href="product.php?id=' . $id . '"><button>Buy Now</button></td>'; 


    } else { 
    $dynamicList .= '<td><img style="padding:10px;/><a href="product.php?id=' . $id . 
    '"><img style="border: #000033 1px solid;" src="inventory_images/' . $id . '.jpg" 
width="200" height="225" alt="' . $product_name . '"/><br/> 
     <width="150" align="left" valign="top" scope="col">' . $product_name . '<br/> 
     Rs.&nbsp;' . $price . '<br/> 
     <a href="product.php?id=' . $id . '"><button>Buy Now</button></td>'; 


    } 
    $i++; 
    } 

    echo $dynamicList; 
    $dynamicList .= '</tr></table>'; 
    } 
    } 
    results.php 
    <?php 
    getcategoryPro(); 
    ?> 
    <p><a href="results.php?sortby=pricehilo">Price (Highest-Lowest)</a></p> 
    <p><a href="results.php?sortby=pricelohi">Price (Lowest-Highest)</a></p> 

при нажатии на мобильные телефоны из выпадающего меню ссылку приходит с продуктом

results.php?category=1

, когда мы нажмем на высокой к низкой ссылку открывается с msg Продукт не найден в этой категории

results.php?sortby=pricelohi

должно быть:

results.php?category=1&sortby=pricelohi

ответ

0
<?php 
getcategoryPro(); 
if (isset ($_GET['category']) && !empty($_GET['category'])) { 
    $cat_id = $_GET['category']; 
} else { 
    // you decide 
} 
?> 
<p><a href="results.php?category=<?= $cat_id ?>&sortby=pricehilo">Price (Highest-Lowest)</a></p> 
<p><a href="results.php?category=<?= $cat_id ?>&sortby=pricelohi">Price (Lowest-Highest)</a></p> 
+0

спасибо, брату это работало –

+0

@rahulJ не могли бы вы отметить ответ как правильный, пожалуйста? :) – Forien

+0

пожалуйста, проверьте это другой вопрос также inventory_list.php Типы

0

Просто измените ссылки на <a href="results.php?category=<?php echo $_GET['category']; ?>&sortby=pricehilo">.

Смежные вопросы