-
Posts
24,551 -
Joined
-
Last visited
-
Days Won
821
Community Answers
-
Barand's post in "New posts" was marked as the answer
Do I take it that a new image is one that is less than 2 weeks old?
$day = date('Y-m-d', strtotime("2023-08-30 16:03:32")); if($day > date('Y-m-d', strtotime('-2 weeks'))){ echo "img src='https://i.imgur.com/0rlIlUD.gif'"; } @requinix - I see what you mean
-
Barand's post in SQL statement with multiple joins - unknown column error was marked as the answer
You don't need any data from the booking table so the last join can go.
At present your query does not know which rooms are booked, and when, as there is no join between room and room_booking tables. Your join to the room_booking table should therefore be ON r.room_id = rb.room_id
How do you know what facilities a room has? There is no room_id in the room_facility table. Instead you have a size id???
Your SELECT has no room_id or room_number so how will you identify the rooms in the results?
-
Barand's post in Access single array element was marked as the answer
For the "[0]" to be needed then the json data would need to be
[{ "id": 1, "item_id": 19, "min_qty": 1, "max_qty": 499, "GBP": 500, "USD": 750, "CAD": 875 }] with the outer [..] to make it an array.
-
Barand's post in How to make visible of unvisible error while inserting data into mariadb database? was marked as the answer
One way is not to turn off the error reporting...
-
Barand's post in Validating password characters was marked as the answer
Do your database , table and db connection all share the same utf8 encoding?
-
Barand's post in Ajax log on handler wrapping redirected to page in response content was marked as the answer
When you send an ajax request to a page, all output then goes into the response that is returned. (ie what you would see if you called that page in your browser is the reponse (which you can use to your advantage to test ajax responders).
Remove the location header from the responder code and do the redirect in the calling page when you receive a succesful response.
-
Barand's post in Current password hashing standard was marked as the answer
password_hash() and password_verify()
-
Barand's post in Duplicating Mysql Table rows but also updating some content was marked as the answer
Start with
SELECT q.id , q.version FROM quote q JOIN ( SELECT client_id , max(version) as version FROM quote WHERE client_id = 15 ) latest USING (client_id, version); +----+---------+ | id | version | +----+---------+ | 71 | 6 | +----+---------+ Now you know that for client #15 the latest quote has id = 71 and its version is 6.
Duplicate quote #71, giving the dupe a verion of 7, and duplicate the items for #71 with the quote_id of the new duped quote.
-
Barand's post in Sql statement join question was marked as the answer
Something like this? ...
SELECT j.id as job_id , j.name , count(q.id) as quotes FROM job j LEFT JOIN quote q ON j.id = q.job_id GROUP BY j.id
-
Barand's post in [Suggestions] - Ordering Items Dynamically was marked as the answer
-- first UPDATE thetable SET display_order = display_order + 1 WHERE display_order >= 2; -- then INSERT INTO thetable (item_name, display_order) VALUES ('Item 4', 2);
-
Barand's post in Build multidimentional array from select was marked as the answer
Oops!
FETCH_GROUP should be FETCH_ASSOC.
You also need to change the order of your selected columns so that the first two are the ones you are using as the keys, then the array_slice takes the rest..
-
Barand's post in For each loop not getting all data was marked as the answer
Shouldn't that be
if(!isset($data[$item['sectionName']])){ ^ What is the relevance of the data you posted to the code?
-
Barand's post in More efficient rounding calculator was marked as the answer
The code you posted was using PHP variable names. ($days, $weeks)
intdiv (x, y) == floor(x/y)
-
Barand's post in On duplicate key update always inserting new row was marked as the answer
You should be getting a mysql error - you have 7 placeholders but only passing 6 values in the execute. The way you have defined it you need to pass the $_POST['quotename'] twice.
A better way is
... ON DUPLICATE KEY UPDATE name=VALUES(name) telling it to use the same value as in the VALUES clause. The you only need provide the name once.
As for your problem, what has to be duplicated to throw a duplicate key error? Your id will be auto_incremented so that won't be duplicated.
-
Barand's post in Insert Ignore was marked as the answer
Just alter the table to add the unique constraint. Run this query...
ALTER TABLE `tablename` ADD UNIQUE INDEX `unq_user_date` (`user_id` ASC, `timestamp` ASC); Checking if it exists first is the worst way to do it.
-
Barand's post in String help was marked as the answer
One way...
$str = "1 x MAKE: Behringer, 1 x MODEL: X-32, 1 x Problem with unit: Not powering on"; $a = explode(': ', $str); unset ($a[0]); foreach ($a as $b) { $results[] = explode(',', $b)[0]; } echo '<pre>results = ' . print_r($results, 1) . '</pre>'; output...
results = Array ( [0] => Behringer [1] => X-32 [2] => Not powering on )
-
Barand's post in Auto generate year session was marked as the answer
Try this. You don't need date arithmetic for years.
$start = 2020; $end = 2029; for ($y=$start; $y<=$end; $y++) { $session = sprintf('%d-%d', $y, $y+1); echo $session . '<br>'; } output
2020-2021 2021-2022 2022-2023 2023-2024 2024-2025 2025-2026 2026-2027 2027-2028 2028-2029 2029-2030
-
Barand's post in passing POST value to CURLOPT_POSTFIELDS was marked as the answer
Perhaps create an array then json_encode it
EG
$user_id = 1234; $data = [ 'user_id' => $user_id , 'name' => 'John Doe' , 'card' => 0 ]; CURLOPT_POSTFIELDS => json_encode($data),
-
Barand's post in mysqli_stmt::bind_param error message was marked as the answer
You are executing a query passing two bound parameter values, but your query has no placeholders for those parameters.
-
Barand's post in php array format from the mysqli_fetch_assoc rows was marked as the answer
You have a situation where a job can have many categories and a category can contain many jobs; a many-to-many relationship. These a resolved by an intermediate table. Your data
model should like this ...
+-------------+ +-----------------+ | job | | category | +-------------+ +--------------------+ +-----------------+ | id |---+ | job_category | +-----| id | | job_title | | +--------------------+ | | cat_description | +-------------+ | | id | | +-----------------+ +---<| job_id | | | category_id |>---+ +--------------------+ so that where you now the equivalent of this for your job table,
+--------+--------------+ | job_id | category_id | +--------+--------------+ | 3 | 2, 4, 5 | | 4 | 1, 2 | +--------+--------------+ you would have a job_category table like this
+----+--------+--------------+ | id | job_id | category_id | +----+--------+--------------+ | 1 | 3 | 2 | | 2 | 3 | 4 | | 3 | 3 | 5 | | 4 | 4 | 1 | | 5 | 4 | 2 | +----+--------+--------------+ Now it's a simple to find which jobs are in a particular category as it is to find which categories a job belongs to.
-
Barand's post in When query is empty was marked as the answer
The first fetch() will return false if no records were found.
if ($result->fetch_assoc()) { // ticket found } else { // ticket not found }
-
Barand's post in Trying to access array of offset with if statement was marked as the answer
Plus, if you are accessing $_SESSION, then you need session_start() at the top of the script.
Also errors in the query
You are trying to match the value in column myid with the string value 'myid' You are trying to order the results by the string value 'id' -
Barand's post in Still some problems was marked as the answer
Then include that condition in your WHERE clause
WHERE (sales.sales_date BETWEEN ? AND ?) AND products.product_id BETWEEN 50 AND 56
-
Barand's post in Php and javascript with timestamp and countdown was marked as the answer
Keep it simple for the user with datetime and time input fields
<form method='POST'> <label for='start'>Auction Start</label> <input type='datetime-local' name='start' id='start'> <br> <label for='duration'>Duration</label> <input type='time' name='duration' id='duration'> <br><br> <input type='submit'> </form>
Store these values in your auction table
CREATE TABLE `auction` ( +----+---------------------+----------+ `id` int(11) NOT NULL AUTO_INCREMENT, | id | start_time | duration | `start_time` datetime DEFAULT NULL, +----+---------------------+----------+ `duration` time DEFAULT NULL, | 1 | 2023-07-17 15:00:00 | 02:30:00 | PRIMARY KEY (`id`) | 2 | 2023-07-18 12:00:00 | 03:00:00 | ) ENGINE=InnoDB;</body> +----+---------------------+----------+ When you want the auction end time for your countdown, query the database and use sql's addtime() function...
SELECT id , start_time as start , duration , addtime(start_time, duration) as finish FROM auction; +----+---------------------+----------+---------------------+ | id | start | duration | finish | +----+---------------------+----------+---------------------+ | 1 | 2023-07-17 15:00:00 | 02:30:00 | 2023-07-17 17:30:00 | | 2 | 2023-07-18 12:00:00 | 03:00:00 | 2023-07-18 15:00:00 | +----+---------------------+----------+---------------------+
-
Barand's post in two different problems stmt and $result was marked as the answer
if (expression) return true else return false is equivalent to
return expression