. I wish to travel a 2 column hierachy and prnt out the following javascript according to what is in the db.

var dogs = new Array("poodle","puli","greyhound");

where var dogs is the parent and poodle, puli, greyhound are the children.

mysql table looks like this

parent title
dogs
dogs poodle
dogs puli
dogs greyhound.

I can print out most of itb using this code. but I cannot close the javascript function beacuse I cant detect the end of the array returned.

function display_children($parent, $level){
// retrieve all children of $parent

$result2 = mysql_query('SELECT title, cat_id, parent from business_categories_hierachy WHERE parent ="'.$parent.'";');

$result2array = mysql_fetch_array($result2);

//echo($result2array);

$comma_separated = explode(",", '$result2array');

while ($row = mysql_fetch_array($result2)){
$cat_id= $row['cat_id'];
$cat_parent= $row['parent'];
//echo "$cat_parent ";
// indent and display the title of this child
if (!$cat_parent) {echo"test";

echo str_repeat('',$level). "var ".$row['title']."= new Array(";

} else {
echo str_repeat('',$level). "\"".$row['title']."\",";
}
// call this function again to display child children

display_children($row['title'], $level+1);

} 

}

display_children('',0);

    you can count the number of results from mysql
    or
    you can store the whole result in a bigger arrary, like this:

    $k=0;
    while ($row = mysql_fetch_array($result2)){ 
    $a[$k]=$row;
    $k++;
    }
    

    and the print it out ... or whatever

      $array = array( 'foo', 'bar', 'bla', 'ble', 'ple', 'fla', 'fle' );
      echo $array[count( $array ) - 1]; // The last value in the array (fle).
      
        18 days later

        THanks very much, I'll post the site you helped make soon.. cheeers

          Originally posted by intenz

          $array = array( 'foo', 'bar', 'bla', 'ble', 'ple', 'fla', 'fle' );
          echo $array[count( $array ) - 1]; // The last value in the array (fle).
          

          [/B]

          echo last($array);

          should also work

            Write a Reply...