Category.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. require_once("DataBase/database.php");
  3. class Category
  4. {
  5. function Category()
  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 .= ", '".$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. }
  55. ?>