Guest User

Untitled

a guest
May 27th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. <?php
  2. <?php
  3. class Category {
  4. public $Ccategory;
  5. private $EndOfStatement;
  6. private $Assembled_Array = array();
  7.  
  8. function __construct ($category_ident = null) {
  9. if ((!isset($category_ident)) || (!is_string($category_ident))) {
  10. $finish = 'LIMIT 30';
  11. } else {
  12. $finish = "WHERE `C_CT_Name`='".$category_ident."' LIMIT 1";
  13. }
  14. $this->EndOfStatement = $finish;
  15. }
  16.  
  17. function assemble () {
  18. $DB = new DB_Func();
  19. $Con = $DB->connect();
  20. $QUERY = "SELECT `C_CID`, `C_CT_Name`, `C_CT_Num_Subs` FROM `c_categories_main` ".$this->EndOfStatement;
  21. $toQuery = mysql_query($QUERY, $Con) or die (mysql_error());
  22. if ((mysql_num_rows($toQuery) == 0) || (mysql_num_rows($toQuery) > 30)) {
  23. return 0;
  24. } else {
  25. $count = mysql_num_rows($toQuery);
  26. $Assemble = array();
  27. $Filled = array();
  28. $row = 1;
  29. for ($i = 0; $i < $count; $i++) {
  30. mysql_data_seek($toQuery,$i);
  31. $fQuery = mysql_fetch_assoc($toQuery);
  32. $HowMany = $fQuery['C_CT_Num_Subs'];
  33. $Value = "`c_categories_".$fQuery['C_CID']."_subcategories`";
  34. $Key = $fQuery['C_CT_Name'];
  35. $Assemble = array ("CatName" => $Key , "Location" => $Value, "NumSubs" => $HowMany);
  36. $Filled = array_fill(0,$row,$Assemble);
  37. }
  38. $this->Assembled_Array = $Filled;
  39. return $this->Assembled_Array;
  40. }
  41. }
  42. }
  43.  
  44.  
  45. include ("category_class.php");
  46. $Category = new Category("Home Services");
  47. $Display = $Category->assemble();
  48. print ("\r\n");
  49. print (var_dump($Display));
  50. ?>
  51.  
  52. Outputs:
  53.  
  54. array(2) {
  55. [0]=> array(3)
  56. {
  57. ["CatName"]=> string(13) "Home Services"
  58. ["Location"]=> string(39) "`c_categories_0000000002_subcategories`"
  59. ["NumSubs"]=> string(2) "01"
  60. }
  61. [1]=> array(3)
  62. {
  63. ["CatName"]=> string(13) "Home Services"
  64. ["Location"]=> string(39) "`c_categories_0000000002_subcategories`"
  65. ["NumSubs"]=> string(2) "01"
  66. }
  67. }
Add Comment
Please, Sign In to add comment