Problema creare link categorii si subcategorii
Scris: Vin Iun 05, 2015
Buna seara, am o nelamurire, cum pot crea link categoriilor? de exemplu index.php?cat=1 interogare in id sau name imi este indiferent.
index :
Functions.php
fiecare categorie sa aiba id lui..
index :
Cod: Selectaţi tot
<?php
require_once 'db_connection.php';
require_once 'functions.php';
?>
<?php
$categoryList = categoryParentChildTree();
foreach($categoryList as $key => $value){
echo $value['name'].'<br>';
}
?>
Cod: Selectaţi tot
<?php
function categoryParentChildTree($parent = 0, $spacing = '', $category_tree_array = '') {
global $dbConnection;
$parent = $dbConnection->real_escape_string($parent);
if (!is_array($category_tree_array))
$category_tree_array = array();
$sqlCategory = "SELECT id,name,parent_id FROM tbl_categories WHERE parent_id = $parent ORDER BY id ASC";
$resCategory=$dbConnection->query($sqlCategory);
if ($resCategory->num_rows > 0) {
while($rowCategories = $resCategory->fetch_assoc()) {
$category_tree_array[] = array("id" => $rowCategories['id'], "name" => $spacing . $rowCategories['name']);
$category_tree_array = categoryParentChildTree($rowCategories['id'], ' '.$spacing . '- ', $category_tree_array);
}
}
return $category_tree_array;
}