<?php
class CART{

  var $id, $otimestamp, $productid, $qtty;

  function __construct(){
	  $this->id = 0;
	  $this->otimestamp = "";
	  $this->productid = "";
	  $this->qtty = "";
  }
  
  function addCart($ptimestamp,$pproductid,$pqtty){
      global $conn;
      $query = "INSERT INTO tb_cart VALUES (null,'$ptimestamp','$pproductid','$pqtty')";
      mysqli_query($conn,$query);
  }
    
  function getCarts(){
      global $conn;
      $query = "SELECT * FROM tb_cart";
      $result = mysqli_query($conn,$query);
      $num = mysqli_num_rows($result);
      if($num>0){
      while($myrow = mysqli_fetch_array($result)){
          $tid = $myrow["id"];
          $output[$tid]["ctimestamp"] = $myrow["ctimestamp"];
          $output[$tid]["productid"] = $myrow["productid"];
          $output[$tid]["qtty"] = $myrow["qtty"];
      }
      }
      return $output;
  }
    
  function getTimestamp(){
	global $conn;
	$query = "SELECT ctimestamp FROM tb_cart ORDER BY ctimestamp DESC LIMIT 0,1";
	$result = mysqli_query($conn,$query);
	while($myrow = mysqli_fetch_array($result)){
	  $output = $myrow["ctimestamp"];
	}
	return $output;
	
  }
	
}
?>