Hi and good day to you guys, I'm trying to create an mlm binary genealogy in php for my project, I'm stuck at creating/displaying the genealogy tree. I've search everywhere and got this code the second answer by Limitless isa this is her JSFiddle. I'v tried to implement it using my function and so far I'm getting nowhere.
Attached here is my database for accounts, and this is my code
<div class="tree">
<ul>
<li>
<div><input type="checkbox">181210-1-105547-1<br/> <button> Test Btn </button></div>
<ul>
<?php
$host = 'localhost';
$name = 'mlm';
$user = 'root';
$pass = '';
$dsn = 'mysql:host=' .$host .';dbname=' .$name;
$options = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_PERSISTENT => true
);
$conn = new PDO($dsn, $user, $pass, $options);
function displayChildren($parent) {
global $conn;
$stmt = $conn->prepare('SELECT * FROM accounts WHERE sponsorUpline = ?');
$stmt->bindValue(1, $parent);
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
echo '<li></div><input type="checkbox">' .$row->serialNumber .'</div></li>';
displayChildren($row->serialNumber);
}
}
displayChildren('181210-1-105547-1');
?>
</ul>
</li>
</ul>
</div>
If anyone could help me with this and explain to me why it's not working would be wonderful.