echo "\n<!-- ################ cat ################### -->\n"; //echo $action; if (isset($action) and !empty($action)) { //Ищем категорию $query = "SELECT * FROM `main` WHERE `url`='{$action}' AND catalog='1'"; $result = mysqli_query($db, $query); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_assoc($result); $title = $row['title']; $keywords = $row['keywords']; $description = $row['description']; $text = $row['pagetext']; echo "<h1 class=\"first\">" . $title . "</h1>"; echo $text; ############# вывод всех продуктов из категорий потомков ############### $idchild = find_parent_id($cat_tree, $row['id']); //Вытавскиваем id категорий всех потомков if (!empty($idchild)) { $query = "SELECT * FROM `product` WHERE cat_id IN(" . $idchild . ")"; //Вытаскиваем все продукты из категорий потомков если такие есть $result3 = mysqli_query($db, $query); if (mysqli_num_rows($result3) > 0) { while ($row3 = mysqli_fetch_assoc($result3)) { $query = "SELECT * FROM img WHERE product_id = {$row3['product_id']}"; //echo $query; $res = mysqli_query($db, $query); $rowimg = mysqli_fetch_assoc($res); $imgpath = '/img/cat/' . $row3['cat_id'] . '/' . $rowimg['name']; //echo $imgpath; build_product($row3['name'], $row3['price'], $imgpath, $row3['url'], $row3['product_id']); }
function find_parent_id($arr, $parent) { //print_arr($arr); if (is_array($arr) and isset($arr[$parent])) { $tree = ''; foreach ($arr[$parent] as $key => $value) { $tree .= $value['id'] . ","; $tree .= find_parent_id($arr, $key); } } else { return null; } return rtrim($tree, ","); }