-
Posts
24,609 -
Joined
-
Last visited
-
Days Won
832
Barand last won the day on June 15
Barand had the most liked content!
About Barand

Profile Information
-
Gender
Male
-
Location
Cheshire, UK
-
Interests
Classical guitar
-
Age
76
- Donation Link
Recent Profile Visitors
105,316 profile views
Barand's Achievements
-
PHP array... $data = [ 'store_id' => 'test', 'api_token' => 'test', 'checkout_id' => 'test', 'txn_total' => '4.00', 'environment' => 'qa', 'action' => 'preload', 'cart' => [ 'items' => [ [ 'description' => 'Item 1', 'unit_cost' => '1.00', 'quantity' => '3' ], [ 'description' => 'Item 2', 'unit_cost' => '1.00', 'quantity' => '1' ] ], 'subtotal' => '4.00' ] ]; $json = json_encode($data); echo $json; gives this json string (spaces and newlines added for readability) { "store_id":"test", "api_token":"test", "checkout_id":"test", "txn_total":"4.00", "environment":"qa", "action":"preload", "cart":{ "items":[ {"description":"Item 1", "unit_cost":"1.00", "quantity":"3" }, { "description":"Item 2", "unit_cost":"1.00", "quantity":"1" } ], "subtotal":"4.00" } }
-
Kamal Hinduja Geneva, Switzerland : Introduction Newbie
Barand replied to kamalhinduja's topic in Introductions
Welcome.- 1 reply
-
- 1
-
-
JSON is a data structure converted to string format to make storage and transfer easier. Define your json as a a PHP string ... $json_str = ' { "store_id":"test", "api_token":"test", "checkout_id":"test", "txn_total":"4.00", "environment":"qa", "action":"preload", "cart":{ "items":[ { "description":"item 1", "unit_cost":"1.00", "quantity":"3" }, { "description":"item 2", "unit_cost":"1.00", "quantity":"1" } ], "subtotal":"4.00" } } '; Provided it is the correct format you use this in the api call. To use the data in PHP you need to decode it with json_decode()... $data = json_decode($json_str, true); # the second parameter "true" converts it to an array. # without it you get a php object. // view the resulting array data echo '<pre>' . print_r($data, 1) . '</pre>'; ... which gives us ... Array ( [store_id] => test [api_token] => test [checkout_id] => test [txn_total] => 4.00 [environment] => qa [action] => preload [cart] => Array ( [items] => Array ( [0] => Array ( [description] => item 1 [unit_cost] => 1.00 [quantity] => 3 ) [1] => Array ( [description] => item 2 [unit_cost] => 1.00 [quantity] => 1 ) ) [subtotal] => 4.00 ) )
-
I'd take the easy way out and use the database with a single query DATA TABLE : season; TABLE : price +-----------+----------------+------------+------------+--------+ +----+--------+------+-------+ | season_id | name | start_date | end_date | tariff | | id | tariff | day | price | +-----------+----------------+------------+------------+--------+ +----+--------+------+-------+ | 1 | Winter 2024 | 2024-11-01 | 2024-12-23 | LO | | 1 | ST | 0 | 70 | day 0 = Monday | 2 | Christmas 2024 | 2024-12-24 | 2025-01-02 | PK | | 2 | ST | 1 | 70 | | 3 | Easter 2025 | 2025-04-11 | 2025-04-27 | PK | | 3 | ST | 2 | 70 | | 4 | Summer 2025 | 2025-06-15 | 2025-08-31 | HI | | 4 | ST | 3 | 70 | +-----------+----------------+------------+------------+--------+ | 5 | ST | 4 | 90 | | 6 | ST | 5 | 90 | | 7 | ST | 6 | 70 | day 6 = Sunday TABLE : tariff | 8 | LO | 0 | 55 | +--------+-------------+ | 9 | LO | 1 | 55 | | tariff | description | | 10 | LO | 2 | 55 | +--------+-------------+ | 11 | LO | 3 | 55 | | HI | High season | | 12 | LO | 4 | 75 | | LO | Low season | | 13 | LO | 5 | 75 | | PK | Peak season | | 14 | LO | 6 | 55 | | ST | Standard | | 15 | HI | 0 | 90 | +--------+-------------+ | 16 | HI | 1 | 90 | | 17 | HI | 2 | 90 | TABLE : booking | 18 | HI | 3 | 90 | +----+------------+---------+------------+ | 19 | HI | 4 | 110 | | id | booking_no | room_no | book_date | | 20 | HI | 5 | 110 | +----+------------+---------+------------+ | 21 | HI | 6 | 90 | | 1 | 1 | 1 | 2025-05-07 | | 22 | PK | 0 | 110 | | 2 | 1 | 1 | 2025-05-08 | | 23 | PK | 1 | 110 | | 3 | 1 | 1 | 2025-05-09 | | 24 | PK | 2 | 110 | | 4 | 2 | 5 | 2025-04-25 | | 25 | PK | 3 | 110 | | 5 | 2 | 5 | 2025-04-26 | | 26 | PK | 4 | 125 | | 6 | 2 | 5 | 2025-04-27 | | 27 | PK | 5 | 125 | | 7 | 2 | 5 | 2025-04-28 | | 28 | PK | 6 | 110 | | 8 | 2 | 5 | 2025-04-29 | +----+--------+------+-------+ | 9 | 2 | 5 | 2025-04-30 | +----+------------+---------+------------+ QUERY SELECT b.booking_no , MIN(b.book_date) as `from` , MAX(b.book_date) as until , SUM(p.price) as total FROM booking b LEFT JOIN season s ON b.book_date between s.start_date AND s.end_date LEFT JOIN price p ON coalesce(s.tariff, 'ST') = p.tariff -- tariff defaults to "ST" if no seasons match date AND p.day = weekday(b.book_date) GROUP BY b.booking_no; +------------+------------+------------+-------+ | booking_no | from | until | total | +------------+------------+------------+-------+ | 1 | 2025-05-07 | 2025-05-09 | 230 | | 2 | 2025-04-25 | 2025-04-30 | 570 | +------------+------------+------------+-------+
-
Trying to use GLOB function to create gallery.
Barand replied to BluApple's topic in PHP Coding Help
<?php $images = glob("path/to/folder a/*.*"); foreach ($images as $i) { echo "<img src='$i'>"; } -
The DATEDIFF() function will give the difference in days. Use TIMESTAMPDIFF() which lets you the specify the units for the result. mysql> SELECT NOW(), timestampdiff(SECOND, '2025-04-26 20:30:00', NOW()) as diff; +---------------------+------+ | NOW() | diff | +---------------------+------+ | 2025-04-26 21:34:51 | 3891 | +---------------------+------+ 1 row in set (0.00 sec) mysql> SELECT NOW(), timestampdiff(MINUTE, '2025-04-26 20:30:00', NOW()) as diff; +---------------------+------+ | NOW() | diff | +---------------------+------+ | 2025-04-26 21:35:22 | 65 | +---------------------+------+ 1 row in set (0.00 sec)
-
How to get the current time and add 10 minutes?
Barand replied to rwahdan1978's topic in PHP Coding Help
If the only reason for that value is to write to the DB then you can do it in the insert query... INSERT INTO tablename (colx, coly, colz) VALUES (?, ?, NOW() + INTERVAL 10 MINUTE) -
Put icon insisde a link EG... <a href='https://facebook.com'> <i class="fa-brands fa-facebook w3-hover-opacity"></i> </a>
-
INSERT INTO `Bank_Reason` (`ID`, `ReasonID`, `Reason`,`Colour`) VALUES (1, 0, '---SELECT','#000000'), (2, 1, 'Other',','#0000ff'), ^^ Again!?
-
INSERT INTO `Bank_Reason` (`ID`, `ReasonID`, `Reason`,Colour') VALUES ^ | unwanted single quote
-
$surname_counts = array_count_values(array_map(fn($v)=>substr($v, strpos($v, '_', 0)+1), $names)); -> Array ( [jones] => 2 [smith] => 3 [doe] => 2 [jackson] => 1 )
-
Generate students postions based on marks scored in an exam
Barand replied to sule's topic in MySQL Help
Put this line just before the mysqli connection code... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); Ensure error_reporting is ON. You should now get error messages if there are problems with a query. -
Generate students postions based on marks scored in an exam
Barand replied to sule's topic in MySQL Help
PS You aren't doing yourself any favours by insisting on mysqli. PDO is a superior library and easier to use. While you are still learning, put your effort into PDO -
Generate students postions based on marks scored in an exam
Barand replied to sule's topic in MySQL Help
Change $pdo = pdoConnect(); to $pdo = new mysqli(HOST, USERNAME, PASSWORD, DATABASE); Job done. -
Generate students postions based on marks scored in an exam
Barand replied to sule's topic in MySQL Help
BTW, it seems a pity that that those students who attain a C6 grade should receive only an anagram instead of a Credit