[eluser]kre8ivdesigns[/eluser]
I want to thank you for your help... I am trying to read as much as possible to figure how to work with MySql. Im a webdesigner but I want to learn Mysql and PHP to build better sites. This is the problem
Home for rent -> Go to website and check availability -> if the home is available -> signup to rent -> if not pick different dates
The way I thought about it is I fill out my firstname, lastname, email, phone, begindate, and numberdays. The form inserts everything into the Client table. The form also inserts into the Avail the dates the room is booked. For Avail table I have it setup where the form strtotime() builds the days based off begindate and numberdays so now I have row for each date. I believe by using this I can check individual days if they are booked.
I am using Doctrine for my database management
Client Model
Code:
class Client extends Doctrine_Record {
//Mysql Table Client
public function setTableDefinition() {
$this->hasColumn('firstname', 'string', 255);
$this->hasColumn('lastname', 'string', 255);
$this->hasColumn('email', 'string', 255);
$this->hasColumn('phone', 'string', 255);
$this->hasColumn('begindate', 'date', 255, array('unique' => 'true'));
$this->hasColumn('numberdays', 'integer', 255);
}
//Mysql Table Client Setup
public function setUp() {
$this->setTableName('client');
$this->actAs('Timestampable');
}
}
Avail Model
Code:
<?php
class Avail extends Doctrine_Record {
//Mysql Table Avail
public function setTableDefinition() {
$this->hasColumn('bookdate', 'date', 255);
$this->hasColumn('user_id', 'integer', 5);
}
//Mysql Table Avail Setup
public function setUp() {
$this->setTableName('avail');
$this->actAs('Timestampable');
}
}
checkavail controller
Code:
<?php
class Checkavail extends Controller {
public function __construct() {
parent::Controller();
$this->load->helper(array('form','url'));
$this->load->library('form_validation');
}
public function index() {
$this->load->view('available');
}
public function submit() {
//input new client
$u = new Client();
$u->firstname = $this->input->post('firstname');
$u->lastname = $this->input->post('lastname');
$u->email = $this->input->post('email');
$u->phone = $this->input->post('phone');
$u->begindate = $this->input->post('begindate');
$u->numberdays = $this->input->post('numberdays');
$u->save();
$id = $this->db->insert_id();
//input dates to book
$date = $this->input->post('begindate');
$days = $this->input->post('numberdays');
$i = 1;
while ($i<$days) {
$newdates = strtotime('+'.$i.' day', strtotime($date));
$booking[$i] = date('Y-m-d', $newdates);
$individualdate = $booking[$i];
//update individual
$u = new Avail();
$u->bookdate = $individualdate;
$u->user_id = $id;
$u->save();
++$i;
}
$this->load->view('submit_success');
}
}
?>
THANKS