Skip to content

Instantly share code, notes, and snippets.

@viniciusmelocodes
Created November 20, 2021 03:43
Show Gist options
  • Save viniciusmelocodes/c78029a2b7464815bd6f3bc7cede05d6 to your computer and use it in GitHub Desktop.
Save viniciusmelocodes/c78029a2b7464815bd6f3bc7cede05d6 to your computer and use it in GitHub Desktop.
/*Connecting to Database tempdb*/
mysql_connect('localhost', 'root');
mysql_select_db('tempdb');
/*Executing the select query to fetch data from table tab_treeview*/
$sqlqry="SELECT * FROM tab_treeview";
$result=mysql_query($sqlqry);
/*Defining an array*/
$arrayCountry = array();
while($row = mysql_fetch_assoc($result)){
$arrayCountry[$row['id']] = array("parent_id" => $row['parent_id'], "name" => $row['name']);
}
/*Checking is there any records in $result array*/
if(mysql_num_rows($result)!=0)
{
/*Calling the recursive function*/
buildTree($arrayCountry, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment