-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Take look at simpleXML.
-
Is this the effect you are looking for? <head> <style type='text/css'> .curved-bottom { clip-path: ellipse(100% 60% at 50% 40%); background-color: #FFFF00; color: black; } .w3-row { background-color: black; color: white; } .w3-col { padding: 50px 0; text-align: center; } </style> </head> <body> <div class='w3-row'> <div class='w3-col m12 curved-bottom'> I have a curvy bottom </div> </div> <div class='w3-row'> <div class='w3-col m12'> I'm a straight guy </div> </div> </body>
-
The only MyIsam-only functionality that I can think of is the ability to have a compound primary key EG PRIMARY KEY (year, number) where the 2nd part auto_increments within the first part, so if you have CREATE TABLE `test1` ( `year` int(11) NOT NULL, `number` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`year`,`number`) ) ENGINE=MyISAM ; mysql> select * from test1; +------+--------+ | year | number | +------+--------+ | 2022 | 1 | | 2022 | 2 | +------+--------+ mysql> insert into test1 (year) values (2022), (2022), (2023), (2023), (2024); mysql> select * from test1; +------+--------+ | year | number | +------+--------+ | 2022 | 1 | | 2022 | 2 | | 2022 | 3 | | 2022 | 4 | | 2023 | 1 | | 2023 | 2 | | 2024 | 1 | +------+--------+
-
There is definitely an echo in here. @Moorcam WRONG! What about UPDATE and DELETE queries?
-
Write it as a CLI script and use a CRON job to run it as frequently as required
-
Then try running it when it isn't December or before 6am.
-
INSERT queries do not have a WHERE clause. You need to to use an "INSERT ... ON DUPLICATE KEY UPDATE ... " EG INSERT INTO table (id, col_a, col_b) VALUES (?, ?, ?) ON DUPLCATE KEY UPDATE col_a = VALUES(col_a), col_b = VALUES(col_b) ;
-
If this is your insert query... INSERT INTO `Customer` (`SyncroID`, `PrimaryContactID`, `CompanyName`, `Address`, `City`, `State`, `Postcode`, `Country`, `AccountStatus`, `UserName`, `Password_Hash`, `Password_Salt`, `Notes`, `BillingContactID`) VALUES ('12321', NULL, 'test', NULL, NULL, 'QLD', NULL, 'Australia', 4, NULL, NULL, NULL, NULL, NULL); ...there is only a 50% correlation between those column names and the data keys in the customer array... -------------------------------------+----------------------------------------- | Matched | Unmatched | -------------------------------------+----------------------------------------- $customer["id"]; $customer["firstname"]; $customer["lastname"]; $customer["business_name"]; $customer["email"]; $customer["address"]; $customer["phone"]; $customer["city"]; $customer["mobile"]; $customer["state"]; $customer["business_and_full_name"]; $customer["zip"]; $customer["business_then_name"]; $customer["fullname"];
-
Firstly, these lines of code do absolutely nothing... $customer["id"]; $customer["firstname"]; $customer["lastname"]; $customer["fullname"]; $customer["business_name"]; $customer["email"]; $customer["phone"]; $customer["mobile"]; $customer["address"]; $customer["city"]; $customer["state"]; $customer["zip"]; $customer["business_and_full_name"]; $customer["business_then_name"]; Secondly, you are using the least efficient means of inserting data that there is. Single inserts are slow. Marginally faster are prepared statements where you prepare once then execute in a loop with new value for each call. By far the fastest way is use multiple inserts. EG INSERT INTO table (id, name) VALUES (1, 'Name A'), (2, 'Name B'), (3, 'Name 3'); To implement... $data = []; foreach ($customers as $c) { $data[] = sprintf("( %d, '%s')", $c['id'], $c['business_name']); } $pdo->exec("INSERT INTO Customer (SyncroID, CompanyName) VALUES " . join(',', $data));
-
Are you sure you don't revisit index.php between runs of page.php? Might be safer if you only set the value if is not already set if (!isset($_SESSION['abc']) { $_SESSION['abc'] = rand(10000, 99999); }
-
-
@Senthilkumar is this any faster than yours? It should get all the data you need in a single query. <?php $sql = "SELECT c.branch , c.printed , c.pending , c.cancelled , c.over7days , c.reminder , y.year , y.yrtotal , y.yrcount , m.month , m.mthtotal , m.mthcount FROM ( SELECT c.branch , sum(status=1) as printed , sum(status=0) as pending , sum(status=2) as cancelled , sum(status=0 AND today <= CURDATE() - INTERVAL 7 DAY) as over7days , sum(first='0000-00-00' AND date <= CURDATE() - INTERVAL 80 DAY) as reminder FROM calibrationdata1 c JOIN userdetails1 u USING (branch) WHERE u.id = ? GROUP BY branch ) c JOIN ( SELECT branch , date_format(date, '%Y') as year , sum(amount) as yrtotal , count(*) as yrcount FROM calibrationdata1 GROUP BY branch, year(date) ) y USING (branch) JOIN ( SELECT branch , date_format(date, '%b') as month , sum(amount) as mthtotal , count(*) as mthcount FROM calibrationdata1 WHERE year(date) = year(curdate()) GROUP BY branch, month(date) ) m USING (branch) "; $res = $pdo->prepare($sql); // NOTE: PDO connection in use $res->execute([ $_SESSION['id'] ?? 16 ]); $counts = []; $yrdata = []; $monthdata = []; foreach ($res as $row) { $counts = array_slice($row, 0, 6); $yrdata[$row['year']] = array_slice($row, 6,3); $monthdata[$row['month']] = array_slice($row, 9); } echo "<table style='width: 600px; margin: 20px; text-align: center'>" . "<tr><th>" . join('</th><th>', array_keys($counts)) . "</th></tr>" . "<tr><td>" . join('</td><td>', array_values($counts)) . "</td></tr>" . "</table>"; echo printArray($yrdata); echo printArray($monthdata); function printArray($arr) { $out = "<table style='width: 200px; margin: 20px; text-align: center'>" . "<tr><th>" . join('</th><th>', array_keys(current($arr))) . "</th></tr>"; foreach ($arr as $a) { $out .= "<tr><td>" . join('</td><td>', array_values($a)) . "</td></tr>"; } $out .= "</table>\n"; return $out; } ?> Example output
-
Yess Phill, you are correct but there will only be a single branch. My original query was SELECT branch , sum(status=1) as printed , sum(status=0) as pending , sum(status=2) as cancelled , sum(status=0 AND today <= CURDATE() - INTERVAL 7 DAY) as over7days , sum(first='0000-00-00' AND date <= CURDATE() - INTERVAL 80 DAY) as reminder FROM calibrationdata c WHERE branch = ? but I changed it on posting to demonstrate that he should be joining to the userdetails table intead of the first query to get the branch
-
Try this to replace your first 6 queries SELECT u.branch , sum(status=1) as printed , sum(status=0) as pending , sum(status=2) as cancelled , sum(status=0 AND today <= CURDATE() - INTERVAL 7 DAY) as over7days , sum(first='0000-00-00' AND date <= CURDATE() - INTERVAL 80 DAY) as reminder FROM calibrationdata c JOIN userdetails u USING (branch) WHERE u.id = 16; +--------+---------+---------+-----------+-----------+----------+ | branch | printed | pending | cancelled | over7days | reminder | +--------+---------+---------+-----------+-----------+----------+ | Mumbai | 8 | 3 | 0 | 3 | 3 | +--------+---------+---------+-----------+-----------+----------+
-
php find earliest date in the format dd/mm/yyyy in a text file
Barand replied to increase's topic in PHP Coding Help
Alternatively usort($data, fn($a, $b) => isoDate($a) <=> isoDate($b)); echo $data[0]; //--> 03/11/2023 06 This is another text in the line function isoDate($text) { $d = substr($text, 0, 10); return DateTime::createFromFormat('d/m/Y', $d)->format('Y-m-d'); } -
php find earliest date in the format dd/mm/yyyy in a text file
Barand replied to increase's topic in PHP Coding Help
use usort() with a callback function which converts the first 10 chars of each line to yyyy-mm-dd format and compares them. -
P.S. Your main problem is the spaghetti coding style you are using, continually moving in and out of php within the html. Try keeping them as separate as possible with php first then the html section. So something like... <?php function yearEntryOptions($current) { $CurrentMonth = date('n'); $opts = ''; for ($i = -1; $i <= 1; $i++) { $y = date('Y') + $i; $sel = $current == $y ? 'selected' : ''; $dis = ($CurrentMonth != 1 && $i == -1) || ($CurrentMonth <= 10 && $i == 1) ? 'disabled' : ''; $opts .= "<option $sel value='$y' $dis>$y</option>\n"; } return $opts; } ?> <html> <body> <select name="YYYY_Entry" style="width:60px"> <?= yearEntryOptions($SE_YYYY_Entry) ?> </select> </body> </html>
-
-
As far as I know, <?php always required whitespace after it.
-
Because it first checks the code for valid syntax before it excutes the code. Syntax errors it does find are "startup errors"
-
I'd start by changing all incidences of <?php} to <?php } ( ie Leave a space after <?php)
-
Give us a clue - what is the error message?
-
One thing to watch for is the stricter variable typing in version 8. Whereas in earlier versions this would work (the empty string being treated as "0") ... $a = 5; $b = ''; echo $a + $b; in version 8 it throws an error