Customers pick When finished If on the book, such as the selection of Van Dyke VT01 from 1/07/59 - 2/07/59-day period, you will not be able to book your car again. It is based on the availability of the vehicle.

I made a separate table Storage booking Van table separately too.

Tables, storage, booked by id_car I take from the table and put the van.

Table of van

This is the code that I defined it booked only three people per day.

$date = "$rn_gostart"; //กำหนดค้นวันที่  

$result = mysqli_query($mysqli,"select * from vn_rent where rn_gostart = '$date'");  
$ckd = mysqli_num_rows($result);  

if($ckd >= 3){  

$msg = "<div class='alert alert-danger'>  
<span class='glyphicon glyphicon-info-sign'></span> &nbsp; วันที่จองเต็มแล้ว  
</div>";  
}else{  

Sorry I am not good at English Please help me

Dani AI

Generated

The current check (matching only the start date) won’t stop overlapping bookings. A robust rule is to test for date-range overlap for the selected vehicle (filter by id_car) and apply the per-day/per-vehicle limit to that result. Two ranges overlap when: start1 <= end2 AND start2 <= end1. If bookings use a half-open interval (checkout day is free), use < instead of <=.

A practical pattern (prepared statements + transaction) — count overlapping bookings for the chosen vehicle and date range, reject if count >= limit, otherwise insert the booking:

$car_id    = 123;
$start     = '2016-07-01'; // YYYY-MM-DD
$end       = '2016-07-02';
$limit     = 3;

$mysqli->begin_transaction();

$stmt = $mysqli->prepare(
  "SELECT COUNT(*) FROM vn_rent
   WHERE id_car = ?
     AND rn_gostart <= ?
     AND rn_rentend   >= ?"
);
$stmt->bind_param("iss", $car_id, $end, $start);
$stmt->execute();
$stmt->bind_result($cnt);
$stmt->fetch();
$stmt->close();

if ($cnt >= $limit) {
  $mysqli->rollback(); // fully booked
} else {
  // insert booking, then commit
  $ins = $mysqli->prepare("INSERT INTO vn_rent (id_car, rn_gostart, rn_rentend) VALUES (?,?,?)");
  $ins->bind_param("iss", $car_id, $start, $end);
  $ins->execute();
  $ins->close();
  $mysqli->commit();
}

Notes and gotchas: index (id_car, rn_gostart, rn_rentend) to speed range queries; use transactions and proper locking to avoid race conditions when multiple clients try to book the same slot simultaneously. SELECT ... FOR UPDATE doesn’t lock non‑existent rows — for strict limits consider a per-day counter table with an atomic UPDATE ... WHERE booked < limit and check affected rows. Always normalize inputs to DATE/DATETIME, use prepared statements to prevent injection, and choose inclusive vs. exclusive end-date semantics and test edge cases.

Regarding dates: as asked, if the UI uses Thai Buddhist years (e.g., “59” for 2559) convert to Gregorian first (Gregorian = BE − 543) so stored queries compare correct YYYY‑MM‑DD values. This ties back to ’s separate booking table and will prevent false negatives from simple = checks.

Hi!

Your thread is marked solved, did you actually solved the issue? Do you care to share your solutions for the readers? Last question: are these 1/07/59 - 2/07/59 Thai calendar dates?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.