Ezilon.com - Target Your Audience, be Seen in Your Region

I need help with this array

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 332 posts

Joined: Feb 2005

I have been struggling with this array for the last couple of days.

I have categories in a database - CID, PID, Name (id, parent category id, name of the category).

So i have a function that will query the database and return an array with all rows and columns so that i can loop through it and format the data on the main page.

Trouble is im pretty sure that i am returning an array with all the data but i cant seem to loop through and get the data out? If that makes sense.

The function takes one parameter and the function will switch on this. It either returns an array or option boxes.

<?php
   
function listcategory($format){
   
       
$categories = $this->query("select * from category");
        if(
mysql_num_rows($categories) <0){
            return
false;
        }else{
       
            switch(
$format){
               
                case
"option":
                    while(
$listcategories = $this->fetcharray($categories)){
                       
$option .="<option value=\"".$listcategories[0]."\">".$listcategories[2]."</option>\n";
                    }
                    return
$option;
                    break;
                   
// this is the array
               
case "array":
                    while(
$thelist = $this->fetcharray($categories)){
                       
$catarray[] = array('id'=>$thelist[0], 'parent'=>$thelist[1], 'name'=>$thelist[2]);
                    }
                    return
$catarray;
                    break;
            }
        }
    }
?>

and when i loop through it just returns what looks like a letter from each field?

<?php
if($admin->managecategory("array") && is_array($admin->managecategory("array"))){
    foreach(
$admin->managecategory("array") as $values){
        foreach(
$values as $thekey=>$thevalue){
            echo
"<div>".$thevalue['name']."".$thevalue['id']."".$thevalue['parent']."</div><br>";
        }
    }
   
}
?>

Please help.

They have: 332 posts

Joined: Feb 2005

I figured it out - had the incorrect variables:

<?php
$array
= $admin->managecategory("array");
if(
$array && is_array($array)){
    for (
$row = 0; $row < count($array); $row++)
    {
        echo
$array[$row]["name"]." ".$array[$row]["parent"]."=>".$array[$row]["name"];
        echo
"<br />";
    }
   
}
?>

The array is fine just getting the data out!

They have: 25 posts

Joined: Aug 2008

Hello ,

where you find difficult i cannot understanding what you want your code is alright ?

Subscribe to this feed: Syndicate content