<?php
class Note{
	    // database connection and table name
	private $conn;
	private $table_name = "note";

	// object properties

	public $id;
	public $city;
	public $date;
    public $note;
	public $entry_by;
	public $entry_date_time;

	public function __construct($db){
		$this->conn = $db;
	}

	function create(){
		$query = "INSERT INTO `" . $this->table_name . "` SET city=:city, date=:date, note=:note, entry_by=:entry_by, entry_date_time=:entry_date_time";

		$stmt = $this->conn->prepare($query);

		$stmt->bindParam(":city", $this->city);
		$stmt->bindParam(":date", $this->date);
		$stmt->bindParam(":note", $this->note);
		$stmt->bindParam(":entry_by", $this->entry_by);
		$stmt->bindParam(":entry_date_time", $this->entry_date_time);

		if($stmt->execute()){
			return true;
		}
		return false;		
	}

	function getAllRows(){

		$query = "SELECT note.* from note right JOIN (SELECT MAX(id) AS mxid FROM note WHERE city=:city AND DATE=:date) AS a ON
        note.id=a.mxid";
		$stmt = $this->conn->prepare( $query );
		if($this->city) $stmt->bindParam(":city", $this->city);
		if($this->date) $stmt->bindParam(":date", $this->date);
		$stmt->execute();
		return $stmt;
	}

	

}
?>