Hey, I have this parent chilid system using a mysql database. Each record looks something like this:
| id | parent_id | name |
| 1 | | test |
| 2 | 1 | test2 |
I am trying to develop a function where you give it the current id you are at, and it will return a array of the id's of all its parents.
This is what I have so far, but it is not working properly.
function getMyParents($start_id) {
global $myParents;
$result = mysql_query("SELECT parent_id FROM hd_categories WHERE id = '$start_id'") or die(mysql_error());
list($parent_id) = mysql_fetch_row($result);
if ($parent_id != "") {
$myParents[] = getMyParents($parent_id);
} else {
$myParents[] = $start_id;
}
return $myParents;
}
All I need it to do is when given the id fromt he current record your at now, it returns a array that holds all the ids of its parents and its own id.
Example:
$myParents[] = $id;
$myParents[] = $nextid;
Thanks for your help!