Hi everybody. I'm trying to print all sub-category items using my own defined PHP function. The purpose of this function is to print all items, which parent value is $parent. There is some thing wrong with this function why it doesn't show information as I wish. To make you understand my aim, suppose that we've items categorized in different groups each has own groups ID. Calling this function I wish to get the all items of same group by feeding of group Id as argument ($parent). Could someone help me to find out the reason why this function doesn’t work, please. Thanks a lot in advance.
<?php
include ('connect.php');
include ('head.html');
echo '<div class="categ"><p class="b">Health</p>';
function retrieve_column($parent){
$sql = "SELECT item FROM category WHERE parent = $parent ORDER BY item ASC";
$r = mysqli_query($dbc, $sql);
if (!$r) {
echo "Couldn’t make a connection to DB.";
} else {
while($row = mysqli_fetch_assoc($r)){
for ($i=0; $i < mysqli_num_rows($r); $i++) {
echo '<a class="text" href="">' . $row['item'][$i] . '</a><br />';
}
}
}
}
$par = 1;
retrieve_column($par);
mysqli_free_r($r);
mysqli_close($dbc);
?>