-
Posts
24,606 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
And if you are worried about storage, a DATETIME (without fractional seconds) only requires 5 bytes.
-
Problem comparing dates, but not getting results.
Barand replied to TapeGun007's topic in MySQL Help
Remove the ";" from the end of that line. It is saying "while(...) do nothing" PS If you only expect a single row for a date, use "if()" instead of "while()". Prepare your statement once before the loop - execute within the loop with new value -
how do i get to remove each item from this code
Barand replied to wixil's topic in Third Party Scripts
If I were a customer, I wouldn't want to remove an item and then end up paying for it because the programmer couldn't be bothered to recalculate. -
how do i get to remove each item from this code
Barand replied to wixil's topic in Third Party Scripts
It looks like you have an item quantity with a minus sign to the left and a plus sign to the right, presumably to amend the quantity. If the quantity is "1" and you click "minus", doesn't that have the effect you want - reduce it to zero? -
ERD for a php function that generates a invoice
Barand replied to webdeveloper123's topic in Application Design
... or reference it anywhere else in the query (eg JOIN ON, WHERE, ORDER BY) -
Yes, thanks - rogue post deleted.
-
My preference would be fetch all the data in a single query but I cannot categorically say it would always be faster.
-
You have the db data and the array, time it. $t1 = microtime(1); for($i=0; $i<1000; $i++) { // method 1 code } %t2 = microtime(1); for($i=0; $i<1000; $i++) { // method 2 code } %t3 = microtime(1); printf("Method 1 took %0.4f seconds<br>", $t2 - $t1); printf("Method 2 took %0.4f seconds<br>", $t3 - $t2);
-
How can one remove unwanted status updates from their profile?
-
As I already said in my earlier reply, you DON'T post the grades and comments to the result table, just store the marks (pcent in my example code).
-
Then output it there.
-
Problem comparing dates, but not getting results.
Barand replied to TapeGun007's topic in MySQL Help
$sqlDate appears to have the correct format (more by good luck than design) so the question is "What format are the dates in the RepairCalendar table?" And that is not how you use prepared queries. $sql = "SELECT * FROM RepairCalendar WHERE DATE(rc_date) = ?"; $stmt = $pdo->prepare($sql); $stmt->execute( [ $sqlDate ] ); The whole point is not to put values directly into the SQL string. -
With <a href="profile.php?username=<?php echo $admin;?>">XXX</a> the bit that is visible in the browser is the text you put where I have XXX https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
-
https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started
-
The usual way to communicate between JS and PHP is by using an AJAX request.
-
I was assuming the problem was that data wasn't available for all dates. If all dates are available then count the records that contain "word", not select the records that contain "word" SELECT s_created_at , SUM(subject LIKE '%word%') as rec_cnt FROM tickets GROUP BY s_created_at ORDER BY s_created_at DESC
-
A useful accessory to any database is a "digit" table containing the numbers 0 - 9. SELECT date , COUNT(s_created_at) as rec_cnt FROM ( SELECT '2022-05-31' - INTERVAL a.num * 1000 + b.num * 100 + c.num * 10 + d.num DAY AS date FROM digit a, digit b, digit c, digit d WHERE '2022-05-31' - INTERVAL a.num * 1000 + b.num * 100 + c.num * 10 + d.num DAY > '2019-04-30' ) last3years LEFT JOIN `tickets` ON last3years.date = tickets.DATE(s_created_at) AND subject LIKE "%Word%" GROUP BY date ORDER BY date DESC
-
How to exclude timeslot in dropdown list | PHP
Barand replied to JacoSwanepoel's topic in PHP Coding Help
Like this $selected_salon = 1; $stmt = $pdo->prepare("SELECT freq FROM slot_frequency WHERE salon_id = ? AND CURDATE() BETWEEN valid_from AND coalesce(valid_until, '9999-12-31') "); $stmt->execute([ $selected_salon]); $freq = $stmt->fetchColumn(); $t1 = new DateTime('08:00:00'); $t2 = new DateTime('17:15'); $step = new DateInterval("PT{$freq}M"); $period = new DatePeriod($t1, $step, $t2); // generate time slots foreach ($period as $d) { $data[] = sprintf("('%s')", $d->format('H:i:s')); } // create temp table $pdo->exec("CREATE TEMPORARY TABLE sb_time_slot ( slot_start_time TIME primary key )"); // insert into the temporary table $pdo->exec("INSERT INTO sb_time_slot(slot_start_time) VALUES " . join(',', $data)); -
How to exclude timeslot in dropdown list | PHP
Barand replied to JacoSwanepoel's topic in PHP Coding Help
Instead of storing the slot times, store the frequency for each salon Table: slot_frequency +----------+------+------------+-------------+ | salon_id | freq | valid_from | valid_until | +----------+------+------------+-------------+ | 1 | 45 | 2022-05-01 | NULL | | 2 | 60 | 2022-05-01 | 2022-05-31 | | 2 | 45 | 2022-06-01 | NULL | +----------+------+------------+-------------+ When you process a booking for salon X, get the frequency in use today and generate a temporary slot table +-----------+ | starttime | +-----------+ | 08:00:00 | | 08:45:00 | | 09:30:00 | | 10:15:00 | | 11:00:00 | | 11:45:00 | | 12:30:00 | | 13:15:00 | | 14:00:00 | | 14:45:00 | | 15:30:00 | | 16:15:00 | | 17:00:00 | just for the duration of this booking -
How to exclude timeslot in dropdown list | PHP
Barand replied to JacoSwanepoel's topic in PHP Coding Help
Don't go away - I'm just about to type up an alternative solution for you -
How to exclude timeslot in dropdown list | PHP
Barand replied to JacoSwanepoel's topic in PHP Coding Help
Not necessarily today - 1, it would be the day before the new ones come into effect Insert new slot times for salon X setting valid_from to Y Update current slots for salon X setting validUntil to Y-1 [edit] Unless you are always changing your practices or opening new salons it is going to be a relatively infrequent process -
How to exclude timeslot in dropdown list | PHP
Barand replied to JacoSwanepoel's topic in PHP Coding Help
Slots 1 - 13 are used every day from until forever (no until date) Slots 14 - 23 are valid until end of May Slots 24 - 36 replace 14 - 23 on June 1st. You use those slots where "'$SelectedDate' BETWEEN valid_from AND valid_until" for required salon SELECT s.slot_start_time FROM sb_time_slots s LEFT JOIN sb_bookings b ON s.slot_start_time = TIME(b.start_time) AND s.salon_id = b.salon_id AND '$SelectedDate' BETWEEN s.valid_from AND s.valid_until AND '$SelectedDate' = b.booking_date WHERE booking_start IS NULL"); -
How to exclude timeslot in dropdown list | PHP
Barand replied to JacoSwanepoel's topic in PHP Coding Help
One possibility, assuming you will also have a salon_id in the booking table too ... +----------+-----------+------------+-------------+---------+ | salon_id | starttime | valid_from | valid_until | slot_id | +----------+-----------+------------+-------------+---------+ | 1 | 08:00:00 | 2022-05-01 | NULL | 1 | | 1 | 08:45:00 | 2022-05-01 | NULL | 2 | | 1 | 09:30:00 | 2022-05-01 | NULL | 3 | | 1 | 10:15:00 | 2022-05-01 | NULL | 4 | | 1 | 11:00:00 | 2022-05-01 | NULL | 5 | | 1 | 11:45:00 | 2022-05-01 | NULL | 6 | | 1 | 12:30:00 | 2022-05-01 | NULL | 7 | | 1 | 13:15:00 | 2022-05-01 | NULL | 8 | | 1 | 14:00:00 | 2022-05-01 | NULL | 9 | | 1 | 14:45:00 | 2022-05-01 | NULL | 10 | | 1 | 15:30:00 | 2022-05-01 | NULL | 11 | | 1 | 16:15:00 | 2022-05-01 | NULL | 12 | | 1 | 17:00:00 | 2022-05-01 | NULL | 13 | | 2 | 08:00:00 | 2022-05-01 | 2022-05-31 | 14 | | 2 | 09:00:00 | 2022-05-01 | 2022-05-31 | 15 | | 2 | 10:00:00 | 2022-05-01 | 2022-05-31 | 16 | | 2 | 11:00:00 | 2022-05-01 | 2022-05-31 | 17 | | 2 | 12:00:00 | 2022-05-01 | 2022-05-31 | 18 | | 2 | 13:00:00 | 2022-05-01 | 2022-05-31 | 19 | | 2 | 14:00:00 | 2022-05-01 | 2022-05-31 | 20 | | 2 | 15:00:00 | 2022-05-01 | 2022-05-31 | 21 | | 2 | 16:00:00 | 2022-05-01 | 2022-05-31 | 22 | | 2 | 17:00:00 | 2022-05-01 | 2022-05-31 | 23 | | 2 | 08:00:00 | 2022-06-01 | NULL | 24 | | 2 | 08:45:00 | 2022-06-01 | NULL | 25 | | 2 | 09:30:00 | 2022-06-01 | NULL | 26 | | 2 | 10:15:00 | 2022-06-01 | NULL | 27 | | 2 | 11:00:00 | 2022-06-01 | NULL | 28 | | 2 | 11:45:00 | 2022-06-01 | NULL | 29 | | 2 | 12:30:00 | 2022-06-01 | NULL | 30 | | 2 | 13:15:00 | 2022-06-01 | NULL | 31 | | 2 | 14:00:00 | 2022-06-01 | NULL | 32 | | 2 | 14:45:00 | 2022-06-01 | NULL | 33 | | 2 | 15:30:00 | 2022-06-01 | NULL | 34 | | 2 | 16:15:00 | 2022-06-01 | NULL | 35 | | 2 | 17:00:00 | 2022-06-01 | NULL | 36 | +----------+-----------+------------+-------------+---------+ In the example data, salon one is on 45 minute slots but salon 2 is on 60 minute slots. On June 1st, salon 2 also changes to 45 minute slots. -
How to exclude timeslot in dropdown list | PHP
Barand replied to JacoSwanepoel's topic in PHP Coding Help
Yes, 1 time per row (normalized). Never use your alternative (unnormalized) structure of muliple values in a single row. CREATE TABLE slot ( starttime TIME NOT NULL PRIMARY KEY ); C -
How to exclude timeslot in dropdown list | PHP
Barand replied to JacoSwanepoel's topic in PHP Coding Help
It will look something like SELECT slot.starttime FROM slot LEFT JOIN sb_booking ON slot.starttime = TIME(booking_start) AND DATE(booking_start) = CURDATE() WHERE booking_start IS NULL