-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Create an intermediate array which restructures your data foreach ($array as $a) { if (!isset($new[$a['u1']])) { $new[$a['u1']] = []; } $new[$a['u1']][] = $a['u2']; } which gives $new array ... Array ( [6] => Array ( [0] => 4 [1] => 3 [2] => 3 [3] => 4 [4] => 11 [5] => 11 ) [3] => Array ( [0] => 4 [1] => 11 [2] => 11 [3] => 4 ) [4] => Array ( [0] => 11 [1] => 11 ) ) Now it's simple to loop through outputting the rows and columns.
-
Should work... mysql> create table users(username varchar(20), password varchar(40)); Query OK, 0 rows affected (0.38 sec) mysql> insert into users(username, password) values('fred', sha1('secret')); Query OK, 1 row affected (0.07 sec) mysql> select * from users where username='fred' and password=sha1('secret'); +----------+------------------------------------------+ | username | password | +----------+------------------------------------------+ | fred | e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4 | +----------+------------------------------------------+ 1 row in set (0.00 sec) BTW, I would recommend you used prepared statements.
-
Be aware that on Friday 3 June, 2022 there is an extra "Jubilee" bank holiday for that year only and the May 30 (Monday) spring bank holiday moves to the following Thursday (June 2). After the line $hols = bankHols(date('Y')); add // Adjust for 2022 only $spring = array_search('2022-05-30', $hols); if ($spring) { $hols[$spring] = '2022-06-02'; // revise date $hols[] = '2022-06-03'; // add Jubilee hol }
-
Help with Enrollment page for my Capstone Project
Barand replied to ray92's topic in PHP Coding Help
$_SESSION['login'] doesn't exist. You need to set the value somewhere. -
XAMPP - INDEX.PHP DISPLAYING AS TEXT IN BROWSER
Barand replied to sdn30studio3's topic in PHP Coding Help
1) Don't post your problems on the Introductions page 2) Use <> button in toolbar when posting code 3) Format your code. Before you process POST data, you need to check that data has been posted to the page and only process if it has. To check... if ($_SERVER['REQUEST_METHOD']=='POST') { // process data } Does the filename that contains that code end with .html or .php ? -
I'd revise the function so it just gave a plain array of dates, then nudge the delivery by a day if the due date is the holiday array. So array is ... Array ( [0] => 2021-01-01 [1] => 2021-04-02 [2] => 2021-04-05 [3] => 2021-05-03 [4] => 2021-05-31 [5] => 2021-08-30 [6] => 2021-12-25 [7] => 2021-12-26 [8] => 2021-12-27 [9] => 2021-12-28 ) My solution: (If you don't want to be spoon-fed, ignore)
-
No need to do that when you can calculate them... function bankHols($yr) { // CALC PUBLIC HOLS FOR $yr $hols = array(); $newyr = "$yr-01-01"; switch (date('w', strtotime($newyr))) { case 6: $newyr = "{$yr}-01-03"; break; case 0: $newyr = "{$yr}-01-02"; break; } $hols['New Year'] = $newyr; $easter = easter_date($yr); $hols['Easter'] = array(date('Y-m-d', strtotime('-2 days', $easter)), date('Y-m-d', strtotime('+1 days', $easter))); $mayday = (new DateTime("first monday of may $yr"))->format('Y-m-d'); $hols['May Day'] = $mayday; $sbank = (new DateTime("last monday of may $yr"))->format('Y-m-d'); $hols['Spring Bank'] = $sbank; $abank = (new DateTime("last monday of august $yr"))->format('Y-m-d'); $hols['August Bank'] = $abank; $x1 = "$yr-12-25"; $x2 = "$yr-12-26"; switch (date('w', strtotime($x1))) { case 5: $x2 = "$yr-12-28"; break; case 6: $x1 = "$yr-12-27"; $x2 = "$yr-12-28"; break; case 0: $x1 = "$yr-12-26"; $x2 = "$yr-12-27"; break; } $hols['Christmas'] = array($x1,$x2); return $hols; } $holidays = bankHols(2021);
-
Check your default timezone setting in your php.ini file. Sounds like it's set to UTC or GMT instead of Europe/London. You can check with echo date_default_timezone_get(); $now = new DateTime(); // using default timezone echo $now->format('H:i:s T') . '<br>'; // 17:05:29 BST $now->setTimezone(new DateTimeZone('UTC')); echo $now->format('H:i:s T') . '<br>'; // 16:05:29 UTC
-
Not necessarily... DATA +-------+-------+ | fruit | price | +-------+-------+ | grape | 5.00 | | melon | NULL | +-------+-------+ Code (PDO) $var = $db->query("select price from fruit where fruit = 'grape'")->fetch()['price'] ?? ''; echo '<br>Grape: ' . $var; $var = $db->query("select price from fruit where fruit = 'melon'")->fetch()['price'] ?? ''; echo '<br>Melon: ' . $var; $var = $db->query("select price from fruit where fruit = 'lemon'")->fetch()['price'] ?? ''; echo '<br>Lemon: ' . $var; Output (No exceptions were thrown during the running of this code) Grape: 5.00 Melon: (why no price?) Lemon: (why no price?)
-
Neither of those conditions I mentioned are "errors" that would generate an error message. However, how you deal with them could be different.
-
If you get back an empty value for the price, how will you know whether it's because the record didn't exist or because there was no price in the record? Most times, when you need a query like that, the value ('small' in this case) will be from the user via GET or POST. Then you need a prepared query, which is going to upset your applecart.
-
Try $start_from = ($page - 1) * $num_per_page;
-
sql| 2005 MSSQL connection error with xampp 1.7.3
Barand replied to DarkVision's topic in Microsoft SQL - MSSQL
Have you tried using Microsoft's sqlsrv library? (i have feeling that replaced the mssql library) Or PDO with SQLserver driver? -
No, it isn't. You'll find that the final " is missing after the "sales-channel" $result .= '"'.$order->sales_channel. "\n"; should be $result .= '"'.$order->sales_channel. "\"\n"; That aside, I can't see multiple writes in the function. My guesses at the moment It is being called multiple times, each call writing a single record. It is being call recursively (What does wp_remote_post( admin_url('admin-ajax.php?action=get_batch_orders_from_api') do inside the function?
-
Your $result string contains only one comma (after the SKU). Where do the others come from in your listed output? Are you sure that's the code causing the problem?
-
Having an unexpected issue with CASE in my query...
Barand replied to Jim R's topic in PHP Coding Help
Your three player_offers results effectively contain +----------------+-------------------+----------------+----------------+--------------+ | player_id | offers | time | commit | decommit | +----------------+-------------------+----------------+----------------+--------------+ | 808 | | | | College B | | 808 | | | College B | | | 808 | College A | 2021-04-15 | | | +----------------+-------------------+----------------+----------------+--------------+ Because the grouping only gives you one row per player, only results from one of them will be chosen by the query to appear. You see the offer data because that is aggregated (GROUP_CONCAT) to one value for the player, but you will process either the commit or decommit (if they are not aggregated.). All you are doing by removing the commit CASE is choosing not to show the data from the row it's chosen to use. -
Having an unexpected issue with CASE in my query...
Barand replied to Jim R's topic in PHP Coding Help
Removing the commit column doesn't change the fact that you have three records for the one player in players_offers. As I said, you'll only get values from one of them as other columns are aggregated. ... exactly. Try making them GROUP_CONCAT (or some other aggregation,eg MAX) like the others -
Can't figure out why HTML blocks won't change
Barand replied to TechnoDiver's topic in PHP Coding Help
I told you that same thing about nl2br() in a previous post of yours. I guess some seeds fall on stony ground. -
Having an unexpected issue with CASE in my query...
Barand replied to Jim R's topic in PHP Coding Help
That is either by good luck or poor checking. If a player has only a single "commit/decommit" record in players_offers, it will work fine. Once you get multiple records you will only see the results from one of them because of the grouping. If you get a result for "commit" you won't see the one for "decommit", and vice versa. -
Having an unexpected issue with CASE in my query...
Barand replied to Jim R's topic in PHP Coding Help
You are using an aggregation function (GRUP_CONCAT) in a query without a GROUP BY clause. The query, therefore, will only return a single row. The values in that row that are not aggregated will be arbitrary. -
PHP: GET JSON from URL and structure it in HTML
Barand replied to Zorglub's topic in PHP Coding Help
All you told us is that the cUrl returns $response. The answer is proportional to the detail in the question. Your "example without authentication" seems to provide your own answer.