Tour.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. require_once("DataBase/database.php");
  3. class Tour
  4. {
  5. function Tour()
  6. {
  7. $this->db = new Database();
  8. }
  9. function create($value)
  10. {
  11. $query = "INSERT INTO ".$this->db->tour_table." VALUES(''";
  12. for($i = 0; $i < count($value); $i++)
  13. $query .= ", '".$value[$i]."'";
  14. $query .= ")";
  15. $this->db->query($query);
  16. }
  17. function update($tour_id, $value)
  18. {
  19. $query = "UPDATE ".$this->db->tour_table." SET ";
  20. $query .= "name='".$value[0]."', ";
  21. $query .= "assistant_id='".$value[1]."' ";
  22. $query .= "WHERE tour_id='".$tour_id."'";
  23. $this->db->query($query);
  24. }
  25. function delete($tour_id)
  26. {
  27. $query = "DELETE FROM ".$this->db->tour_table." WHERE tour_id='$tour_id'";
  28. $this->db->query($query);
  29. }
  30. function get($tour_id = "", $row_names = array(), $search = "")
  31. {
  32. if($tour_id == "")
  33. {
  34. if(count($row_names) == 0)
  35. $query = "SELECT * FROM ".$this->db->tour_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->tour_table;
  42. }
  43. if($search != "")
  44. $query .= " WHERE ".$search;
  45. $query .= " ORDER BY tour_id ASC";
  46. return $this->db->fetchRows($this->db->query($query));
  47. }
  48. else
  49. {
  50. $query = "SELECT * FROM ".$this->db->tour_table." WHERE tour_id='".$tour_id."'";
  51. $query .= " ORDER BY tour_id ASC";
  52. return $this->db->fetchRows($this->db->query($query));
  53. }
  54. }
  55. function getByAssistant($assistant_id)
  56. {
  57. if($assistant_id == "")
  58. {
  59. $query = "SELECT * FROM ".$this->db->tour_table;
  60. $query .= " WHERE assistant_id='".$assistant_id."' ";
  61. $query .= " ORDER BY tour_id ASC";
  62. return $this->db->fetchRows($this->db->query($query));
  63. }
  64. }
  65. }
  66. ?>