}
$where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
// get the total number of records
$query = 'SELECT *'
. ' FROM reserv a left join profile b on a.ProfileID = b.ProfileID left join statusreserv c on a.StatusID = c.StatusID'
. $where
. ' order by a.ReservID DESC'
;
$a = $row->ReservID;
$db =& JFactory::getDBO();
$query = "SELECT * FROM reserv a left join profile b on a.ProfileID = b.ProfileID left join province c on a.ProID = c.ProID WHERE ReservID = '$a'";
$db->setQuery( $query );
$user = $db->loadObject();
$query2 = "SELECT * FROM driver a LEFT JOIN reserv b ON a.DriverID = b.DriverID WHERE StatusID = '2' AND ((Date('$user->StartDate')BETWEEN StartDate AND EndDate) AND (Date('$user->EndDate') BETWEEN StartDate AND EndDate)) OR ((StartDate BETWEEN Date('$user->StartDate') AND Date('$user->EndDate')) AND (EndDate BETWEEN Date('$user->StartDate') AND Date('$user->EndDate'))) ";
$db->setQuery( $query2 );
$user2 = $db->loadObject();
$query3 = "SELECT a.CarID FROM car a left join brand b on a.BrandID = b.BrandID left join reserv c on a.CarID = c.CarID WHERE StatusID = '2' AND ((Date('$user->StartDate')BETWEEN StartDate AND EndDate) AND (Date('$user->EndDate') BETWEEN StartDate AND EndDate)) OR ((StartDate BETWEEN Date('$user->StartDate') AND Date('$user->EndDate')) AND (EndDate BETWEEN Date('$user->StartDate') AND Date('$user->EndDate'))) ";
$db->setQuery( $query3 );
$user3 = $db->loadObject();
$database2 =& JFactory::getDBO();
//$car = array();
$car = array('0' => array('value' => '', 'text' => '-- ยังไม่ทำการเลือก --'));
$database2->setQuery( "SELECT a.CarID, CONCAT(TypeName,' :: ',BrandName,' :: ',CarName,' :: ',CarNumber) AS totalcar FROM car a left join brand b on a.BrandID = b.BrandID left join type c on a.TypeID = c.TypeID WHERE a.CarID = '$row->CarID' OR a.CarID != '$user3->CarID' GROUP BY a.CarID ");
$car = array_merge( $car, $database2->loadObjectList() );
$lists['car'] = JHTML::_('select.genericList', $car, 'CarID', 'class="inputbox" '. '', 'CarID','totalcar', $row->CarID );