I used the adjacency list model for my table in MySQL, along with a PHP function recursion to query and realised it slows down the website. Is there an alternative model i could use that i can use one query to get both parent and child elements, without recursion?
The table structure is like this:
myTable:
+----+----------+
| id | parentID |
+----+----------+
| 1 | null |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 4 |
-----------------
I'm using a recursion query like below:
function queryf($id) {
$query = mysql_query("SELECT * FROM `Table` WHERE id='$id'",$this->connect);
while($row = mysql_fetch_assoc($query)) {
$sid = $row['id'];
//code
$this->$queryf($sid);
}
}