Advertisement
apl-mhd

tree database

Dec 24th, 2018
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: apelmahmud
  5.  * Date: 02/04/2017
  6.  * Time: 3:24 PM
  7.  */
  8.  
  9.  
  10.  
  11.     $serverName = 'localhost';
  12.     $userName = 'root';
  13.     $pass = '';
  14.     $dbname = 'HR';
  15.  
  16.     $name ="orko";
  17.  
  18.     $con = new  mysqli($serverName,$userName,$pass,$dbname);
  19.  
  20.     if($con->connect_error){
  21.  
  22.         die("connect fail");
  23.     }
  24.  
  25.    // $sql = 'select * from employees where employee_id = 3000';
  26.  
  27.    
  28.  
  29.  
  30. function tree($parent){
  31.    
  32.     global $con;
  33.     $sql = "select * from employees where manager_id =$parent";  
  34.     $result =  $con->query($sql);
  35.  
  36.     while ($row = $result->fetch_assoc()) {
  37.             echo $row['EMPLOYEE_ID']." ".$row['FIRST_NAME']."<br>";
  38.             tree($row['EMPLOYEE_ID']);
  39.    
  40.     }
  41.  
  42. }
  43.  
  44.  
  45.     tree(3);
  46.    
  47.        
  48.        
  49.    
  50.  
  51.  
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement