-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
PHP - How to take an image from an array and save it to MYSQL?
Barand replied to Zorglub's topic in PHP Coding Help
What does this output? echo '<pre>' . print_r($vehicle, 1) . '</pre>'; -
If you change the query to this $sql = "UPDATE users SET name = :name, email = :email, phone = :phone, address = :address, license_number = :license_number, position = :position, role = :role, submittedby = :submittedby, image = COALESCE(:image, image) WHERE id = :id "; then, if :image is NULL, the existing value will not be changed.
-
I'd be inclined to do all the filtering required on the order in the subquery, ensuring there is only one row per order otherwise it throws the pagination. For example, if I only wanted to report orders that had sold widgets or gizmos SELECT o.order_id , customer , p.name , p.quantity FROM ( SELECT DISTINCT o1.order_id , concat(firstname, ' ', lastname) as customer FROM oc_order o1 JOIN oc_order_product op ON o1.order_id = op.order_id AND op.name IN ( 'gizmo' , 'widget' ) ORDER BY order_id LIMIT 0, 2 -- <- paginate here ) o JOIN oc_order_product p USING (order_id); As for relative speeds of alternatives, benchmark them (example).
-
OOP point to array value inside of a stdClass Object
Barand replied to jaybo's topic in PHP Coding Help
-> for object properties [] for array keys So $response->data->result[0]->value -
OOP point to array value inside of a stdClass Object
Barand replied to jaybo's topic in PHP Coding Help
Agreed. You do realize that it's objects and not arrays? -
OOP point to array value inside of a stdClass Object
Barand replied to jaybo's topic in PHP Coding Help
What's wrong with using "0"? -
I'd suggest something like this if($_SERVER['REQUEST_METHOD']=='POST') { $post = array_map('trim', $_POST); unset($post['submit']); // not wanted on journey $post['id'] = trim($_SESSION['id']); $post['submittedby'] = trim($_SESSION["username"]); if ($_FILES['image']['error'] = UPLOAD_ERR_OK) { // image file directory $target = "images/".basename($_FILES['image']['name']); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; $post['image'] = $target; }else{ $msg = "Failed to upload image"; $post['image'] = null; } } else { $post['image'] = null; } try { $sql = "UPDATE users SET name = :name, email = :email, phone = :phone, address = :address, license_number = :license_number, position = :position, role = :role, submittedby = :submittedby, image = :image WHERE id = :id "; $stmt= $db->prepare($sql); $stmt->execute($post); $message = ' <i class="fa fa-check text-success"> Record Updated!</i>'; } catch (PDOException $e) { $message = ' <i class="fa fa-check text-danger"> Something went wrong please contact the server admin.</i>'; } }
-
You aren't providing the values for the placeholders when you execute the query. Turn on the error reporting. Also you aren't specifying which row to update, so you will apply the same update to them all.
-
sending email with info from mysql database inserted
Barand replied to Gunnyk's topic in PHP Coding Help
What have you tried so far? -
Randomizing posts in word press - by a random seed + a day variable
Barand replied to maberg's topic in PHP Coding Help
You could just forget about the session value and SELECT ... ORDER BY RAND(dayofyear(CURDATE())) -
Display MQTT data on php page without refreshing the page.
Barand replied to michelle1404's topic in Javascript Help
Good luck with that. The MQTT is javascript, which runs in the client browser. PHP runs on the server. -
Display MQTT data on php page without refreshing the page.
Barand replied to michelle1404's topic in Javascript Help
I have moved it for you. -
Display MQTT data on php page without refreshing the page.
Barand replied to michelle1404's topic in Javascript Help
Does this help? -
I get it now. (I'll take the order example as I happened to have a convenient pair of test tables) TABLE: oc_order +----------+-----------+----------+------------+-----------------+ | order_id | firstname | lastname | date_added | order_status_id | +----------+-----------+----------+------------+-----------------+ | 1 | Hugh | Jass | 2020-05-01 | 1 | | 2 | Laura | Norder | 2020-05-03 | 1 | | 3 | Tom | DiCanari | 2020-05-05 | 1 | | 4 | Peter | Dowt | 2020-05-07 | 1 | +----------+-----------+----------+------------+-----------------+ 4 rows in set (0.00 sec) TABLE: oc_order_product +------------------+----------+-------------+----------+ | order_product_id | order_id | name | quantity | +------------------+----------+-------------+----------+ | 1 | 1 | Gizmo | 2 | | 2 | 1 | Widget | 5 | | 3 | 1 | Wotsit | 1 | | 4 | 2 | Thingy | 2 | | 5 | 2 | Widget | 1 | | 6 | 2 | Thingumajig | 1 | | 7 | 3 | Gizmo | 20 | | 8 | 3 | Widget | 15 | | 9 | 4 | Gizmo | 25 | | 10 | 4 | Thingy | 5 | | 11 | 4 | Wotsit | 10 | +------------------+----------+-------------+----------+ PROBLEM: to produce a paginated result with 2 orders per page SOLUTION: Use a paginated subquery for the orders instead of the order table itself PAGE 1 SELECT o.order_id , customer , p.name , p.quantity FROM ( SELECT order_id , concat(firstname, ' ', lastname) as customer FROM oc_order ORDER BY order_id LIMIT 0, 2 -- <- paginate here ) o JOIN oc_order_product p USING (order_id) +----------+--------------+-------------+----------+ | order_id | customer | name | quantity | +----------+--------------+-------------+----------+ | 1 | Hugh Jass | Gizmo | 2 | | 1 | Hugh Jass | Widget | 5 | | 1 | Hugh Jass | Wotsit | 1 | | 2 | Laura Norder | Thingy | 2 | | 2 | Laura Norder | Widget | 1 | | 2 | Laura Norder | Thingumajig | 1 | +----------+--------------+-------------+----------+ PAGE 2 SELECT o.order_id , customer , p.name , p.quantity FROM ( SELECT order_id , concat(firstname, ' ', lastname) as customer FROM oc_order ORDER BY order_id LIMIT 2, 2 ) o JOIN oc_order_product p USING (order_id) +----------+--------------+--------+----------+ | order_id | customer | name | quantity | +----------+--------------+--------+----------+ | 3 | Tom DiCanari | Gizmo | 20 | | 3 | Tom DiCanari | Widget | 15 | | 4 | Peter Dowt | Gizmo | 25 | | 4 | Peter Dowt | Thingy | 5 | | 4 | Peter Dowt | Wotsit | 10 | +----------+--------------+--------+----------+
-
Are you sure this is a database table and not a spreadsheet? Can you show a sample of the data to ilustrate the problem? It's difficult to imagine why this might be the case.
-
If you want a wavy line, just generate a sine wave.
-
The first one looks to me like it was created with ✶ or similar
-
You gotta be joking. There's only one true Editor - PHPEd 😁 - and so it begins.
-
An earlier post of yours shows you apparently disapprove of people posting solutions, so why should we?
-
While you're in a receptive mood I have another couple of recommendations for you. Use prepared statements so you aren't putting data values directly into the queries. Switch to PDO from mysqli. It's far more streamlined and makes (1) above much easier.
-
BTW, the time_start, time_end, break_time columns in your stafftime table should be type TIME, not VARCHAR.
-
How you do it depends on how you are entering the data. The are basically two approaches... Create the timesheet record first then, each day add that days stafftime record Have a form where you enter the timesheet header data and all days' times at once for a user. If you use the first, have a dropdown so the user can select the timesheet record id and write that id with the day's times into stafftime. Doing it the second way, on posting the form you would first write the timesheet record (id would be an autoincrement column) then call lastInserId() to get the id of that new record. You then insert the time records with that last inserted id as the sheet_id.