Guest User

Untitled

a guest
May 26th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <?php
  2. require "SQL_Object.php";
  3.  
  4. // Example extended class
  5. class forumObject extends SQL_Object {
  6.     function buildForum() {
  7.         $sql = "SELECT * FROM `forum_cats` WHERE `PID` = '{$this->data[$this->pointer]['ID']}'";
  8.         $this->object[$this->pointer]['Forum'] = new forumObject($sql);
  9.     }
  10. }
  11.  
  12. // Make sure you connect to your database first.
  13. $id_link = mysql_connect("localhost", "user", "password");
  14. mysql_select_db("database");
  15.  
  16. // ------------------------------------------------
  17.  
  18. // Example Recursive Forum Builder.
  19. function buildForumCategories($forums) {
  20.     // Build a container so the child boards indent.
  21.     echo "<div style=\"margin-left: 10px;\">";
  22.    
  23.     // We can use foreach to increment the internal pointer on the class.
  24.     foreach ($forums as $key => $forum) {
  25.         // Echo the forum name. (The field name is the MySQL row or whatever you specified in the query.
  26.         echo $forums->name . "<br />";
  27.        
  28.         // We can see if there are any child forums using count.
  29.         // $forums->Forum will invoke PHP 5's magic method "__get"
  30.         // SQL_Object also implements countable interface so we can
  31.         // override the count function with our own.
  32.         if (count($forums->Forum) > 0) {
  33.             // Call child boards.
  34.             buildForumCategories($forums->Forum);
  35.         }
  36.     }
  37.     // We can also manually do it with a for:
  38.     //      Example: for ($forums->rewind(); $forums->valid(); $forums->next())
  39.     //
  40.     // We could use the internal objects, but the methods work just fine.
  41.    
  42.     echo "</div>";
  43. }
  44.  
  45. // Do you're normal query for the initial boards.
  46. $sql = "SELECT * FROM `forum_cats` WHERE `PID` = 0";
  47.  
  48. // Pass the query to the extended class.
  49. $forums = new forumObject($sql);
  50.  
  51. // Build the forum
  52. buildForumCategories($forums);
Add Comment
Please, Sign In to add comment