Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function createTree($user_ids, $depth)
- {
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "fiverocks_temp";
- $depth--;
- if($depth == 0 or count($user_ids) == 0) return;
- for($i = 0; $i < count($user_ids); $i++)
- {
- // echo "<br>";
- // for($j = 0; $j < 5 - $depth; $j++) {
- // echo "------";
- // }
- echo '{text: "'.$user_ids[$i].'",';
- $conn = new mysqli($servername, $username, $password, $dbname);
- $sql = "SELECT * FROM reference where referred_by = $user_ids[$i];";
- $result = $conn->query($sql);
- if($result->num_rows != 0)
- {
- echo 'nodes: [';
- $users = array();
- $j = 0;
- while($row = $result->fetch_assoc()) {
- $users[$j] = $row['referred_to'];
- $j++;
- }
- createTree($users, $depth);
- echo '],';
- }
- echo '},';
- }
- }
- $users = array();
- $users[0] = 1;
- $depth = 6;
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Bootstrap Tree View</title>
- <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.css" rel="stylesheet">
- <link href="css/bootstrap-treeview.css" rel="stylesheet">
- </head>
- <body>
- <div class="container">
- <h1>Bootstrap Tree View</h1>
- <br>
- <div class="row">
- <div class="col-sm-4">
- <h2>Default</h2>
- <div id="treeview1" class=""></div>
- </div>
- </div>
- </div>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-treeview/1.2.0/bootstrap-treeview.min.js"></script>
- <script type="text/javascript">
- $(function() {
- <?php
- echo "var tree = [";
- createTree($users, $depth);
- echo "]";
- ?>
- $('#treeview1').treeview({
- data: tree
- });
- });
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment