Hi, I employed a coder a while ago who wrote the following functions. It does work on *some* servers, but recently have experienced problems of the output not being displayed on several servers. It's lost on me right now. If anyone could take a look, rework the code or suggest improvements which ends up in it working on all servers I would be very grateful.. plus I will PayPal $10 and +Rep for your help as it's only fair. So.. Function set: function cat_list($cat_id=0,$parent_id=0) { global $database; $cats=array(); //get categories in hierarchy cat_array($cat_id,$parent_id,$cats); for($ctr=0;$ctr<count($cats);$ctr++) { $qry="select * from category where cat_id=".$cats[$ctr]; $result = $database->query($qry,MYSQL_ASSOC); $row=$result[0]; $sel= $cat_id==$row["cat_id"]?" selected ":""; echo "<option value=\"{$row["cat_id"]}\" $sel>".get_cat_pad($row["cat_id"]).$row["cat_name"]."</option>"; } } //end cat_list // start cat_array function cat_array($cat_id=0,$parent_id=0,$cats) { global $database; $qry="select cat_id,cat_name from category where parent_id=$parent_id "; $qry .=" order by cat_name"; $result=$database->query($qry,MYSQL_ASSOC); if($result==MYSQL_NO_RESULTS) return; foreach($result as $value) { $row=$value; $cats[]=$row["cat_id"]; cat_array($cat_id,$row["cat_id"],$cats); } } PHP: Function called: <select name="parent_id"><option value="0">TOP LEVEL</option> <?php $parent_id=""; echo cat_list($parent_id); ?> </select> PHP:
All that is show is the 'TOP LEVEL' select option. There should be further options listing the category names selected from the database table. I know it's something to do with either the count or array, or both. As elsewhere I rewrote the data selection and it worked on all servers. Is there a server or PHP setting that could be influencing this?
I'm not sure, but I don't really like the way (s)he coded it, so here is my version; function cat_list($cat_id=0,$parent_id=0){ global $database; $qry = "SELECT `cat_id`,`cat_name` FROM `category` WHERE `parent_id` = '$parent_id' order by `cat_name`"; $result = $database->query($qry,MYSQL_ASSOC); if($result!=MYSQL_NO_RESULTS){ foreach($result as $value){ echo "<option value=\"{$value["cat_id"]}\">".get_cat_pad($value["cat_id"]).$value["cat_name"]."</option>"; } } } Code (markup): Can I see the query function?