Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. require_once(__DIR__."/../includes/config.php");
  2. require_once(__DIR__."/../includes/functions.php");
  3. startSession();
  4. define('DSN','mysql:host=localhost;dbname=solvedesktop');
  5. define('USERNAME' , 'root');
  6. define('PASSWORD' , '');
  7.  
  8. try {
  9. $DB = new PDO(DSN, USERNAME, PASSWORD);
  10. } catch(PDOException $e) {
  11. echo $e->getMessage();
  12. }
  13.  
  14. try {
  15. if(isset($_SESSION["id"])){
  16. $sql = "SELECT * FROM drop_down WHERE published = 1 AND loggedin = 1";
  17. $result = $DB->query($sql);
  18. $row_count = $result->rowCount();
  19. if($row_count){
  20. $rows = $result->fetchAll(PDO::FETCH_ASSOC);
  21. }
  22. } else {
  23. $sql = "SELECT * FROM drop_down WHERE published = 1 AND loggedin = 0";
  24. $result = $DB->query($sql);
  25. $row_count = $result->rowCount();
  26. if($row_count){
  27. $rows = $result->fetchAll(PDO::FETCH_ASSOC);
  28. }
  29. }
  30. catch(PDOException $e) {
  31. echo $e->getMessage();
  32. }
  33. }
  34.  
  35. <?php
  36. $items = $rows;
  37. $id = '';
  38. echo "<ul class ='multidrop'>";
  39. foreach($items as $item){
  40. if($item['parent_id'] == 0){
  41. echo "<li><a href=../home/view.php?id=".$item['id'].">".$item['title']."</a>";
  42. $id = $item['id'];
  43. sub($items, $id);
  44. echo "</li>";
  45. }
  46. }
  47. echo "</ul>";
  48. function sub($items, $id){
  49. echo "<ul>";
  50. foreach($items as $item){
  51. if($item['parent_id'] == $id){
  52. echo "<li><a href=../home/view.php?id=".$item['id'].">".$item['title']."</a>";
  53. sub($items, $item['id']);
  54. echo "</li>";
  55. }
  56. }
  57. echo "</ul>";
  58. }
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement