Category.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. require_once("DataBase/database.php");
  3. class Category
  4. {
  5. function __construct()
  6. {
  7. $this->db = new Database();
  8. }
  9. function create($value)
  10. {
  11. $query = "INSERT INTO ".$this->db->category_table." VALUES('".$value[0]."'";
  12. for($i = 1; $i < count($value); $i++)
  13. $query .= ", '".str_replace("'", "\'", $value[$i])."'";
  14. $query .= ")";
  15. $this->db->query($query);
  16. }
  17. function update($category_id, $value)
  18. {
  19. $query = "UPDATE ".$this->db->category_table." SET ";
  20. $query .= "name='".$value[0]."', ";
  21. $query .= "details='".$value[1]."' ";
  22. $query .= "WHERE category_id='".$category_id."'";
  23. $this->db->query($query);
  24. }
  25. function delete($category_id)
  26. {
  27. $query = "DELETE FROM ".$this->db->category_table." WHERE category_id='$category_id'";
  28. $this->db->query($query);
  29. }
  30. function get($category_id = "", $row_names = array(), $search = "")
  31. {
  32. if($category_id == "")
  33. {
  34. if(count($row_names) == 0)
  35. $query = "SELECT * FROM ".$this->db->category_table;
  36. else
  37. {
  38. $query = "SELECT ".$row_names[0];
  39. for($i = 1; $i < count($row_names); $i++)
  40. $query .= ", ".$row_names[$i];
  41. $query .= " FROM ".$this->db->category_table;
  42. }
  43. if($search != "")
  44. $query .= " WHERE ".$search;
  45. $query .= " ORDER BY category_id ASC";
  46. return $this->db->fetchRows($this->db->query($query));
  47. }
  48. else
  49. {
  50. $query = "SELECT * FROM ".$this->db->category_table." WHERE category_id='".$category_id."' ORDER BY category_id ASC";
  51. return $this->db->fetchRows($this->db->query($query));
  52. }
  53. }
  54. function getABC($category_id = "", $row_names = array(), $search = "")
  55. {
  56. if($category_id == "")
  57. {
  58. if(count($row_names) == 0)
  59. $query = "SELECT * FROM ".$this->db->category_table;
  60. else
  61. {
  62. $query = "SELECT ".$row_names[0];
  63. for($i = 1; $i < count($row_names); $i++)
  64. $query .= ", ".$row_names[$i];
  65. $query .= " FROM ".$this->db->category_table;
  66. }
  67. if($search != "")
  68. $query .= " WHERE ".$search;
  69. $query .= " ORDER BY name ASC";
  70. return $this->db->fetchRows($this->db->query($query));
  71. }
  72. else
  73. {
  74. $query = "SELECT * FROM ".$this->db->category_table." WHERE category_id='".$category_id."' ORDER BY category_id ASC";
  75. return $this->db->fetchRows($this->db->query($query));
  76. }
  77. }
  78. }
  79. ?>