czy można to jakos zrobić by było jako jedno zapytanie do bazy ?

  1. <?php
  2.  
  3. $query = "select * from ".$prefix."store_inventory where cat_id='$cat_id' AND p_akt='1' order by popularity desc LIMIT 5"; 
  4.  
  5. $result_t = mysql_query($query);
  6. $count_t = mysql_num_rows($result_t);
  7. if($count_t==0){
  8. $sql_select_k = mysql_query( "SELECT * FROM ".$prefix."store_category where cat_father_id = '$cat_id' order by rand() desc LIMIT 1");
  9. while ($row = mysql_fetch_array($sql_select_k))
  10. {
  11. $query = "select * from ".$prefix."store_inventory where cat_id='$cat_id' AND p_akt='1' order by popularity desc LIMIT 5"; 
  12. }
  13. }
  14.  
  15. ?>


np łącząc ze ma wybrać z najpierw kategorie a potem z niej produkty