Hi I am trying to create a hierarchy array from our mysql database.
What i have so far is:
//instantiate DB & connect
$database = new Database();
$db = $database->connect();
//instantiate question object
$question = new Question($db);
//query
$results = $question->read();
//check for data
if ($results) {
$question_arr['questions'] = array();
$child_arr = array();
while ($row = $results->fetch(PDO::FETCH_ASSOC)) {
a
I have no idea what you are starting with or what you want to finish with, so here is general method of dealing with a hierarchy.
category table
+--------+-----------+--------+
| cat_id | catname | parent |
+--------+-----------+--------+
| 1 | Cat 1 | 0 |
| 2 | Cat 2 | 0 |
| 3 | Cat 3 | 0 |
| 4 | Cat 1 1 | 1 |
| 5 | Cat 1 2 | 1 |
| 6 | Cat 2 1 | 2 |
| 7 | Cat 2 2 | 2 |
| 8 | Cat 2 3 |