Generate a html tree with php from a specific user using mysql

D

Davit

Guest
I would like to generate a tree from the following tables: TBLPROJECTS Id Name mainprojectid (this is the parentid, this is 0 by default unless it is part of another project)

TBLUSERPROJECTS userprojectid userid projectid

TBLUSERS id name

I now have the following code:

require_once 'php/connectie.php';
if (isset($_SESSION['klantid'])){
$klantid = $_SESSION['klantid'];
function categoryParentChildTree($parent = 0, $spacing = '', $category_tree_array = '') {
global $connectie;
global $klantid;
$parent = $connectie->real_escape_string($parent);
if (!is_array($category_tree_array))
$category_tree_array = array();

$sqlCategory = "SELECT id,name,mainprojectid FROM projects WHERE mainprojectid = $parent ORDER BY id ASC";
$resCategory=$connectie->query($sqlCategory);

if ($resCategory->num_rows > 0) {
while($rowCategories = $resCategory->fetch_assoc()) {
$category_tree_array[] = array("id" => $rowCategories['id'], "name" => $spacing . $rowCategories['name']);
$category_tree_array = categoryParentChildTree($rowCategories['id'], '    '.$spacing . '- ', $category_tree_array);
}
}
return $category_tree_array;
}

$categoryList = categoryParentChildTree();
foreach($categoryList as $key => $value){
$name= $value['name'];
$id= $value['id'];
echo '
<form action="" method="post">
<p> '.$name.' <button value="'.$id.'" name="addproject" type="submit">+</button> <button value="'.$id.'" name="checkproject" type="submit">Tijdregistratie</button> </p>
</form> <br> ';
}}


This generates a tree of all the projects but not from one specific user. When I try this SQL:

SELECT id,name,mainprojectid FROM userproject JOIN projects ON projects.id = userproject.project_id WHERE user_id = 3


it just goes into an infinite loop... So I'm kinda stuck now.

Continue reading...
 
Top