Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. RTFM mysqli_query() requires 2 arguments. There is more to switching from mysql_xxx() to mysqli_xxx() than just adding an "i". They are completely different animals.
  2. Take look at simpleXML.
  3. 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>
  4. 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 | +------+--------+
  5. There is definitely an echo in here. @Moorcam WRONG! What about UPDATE and DELETE queries?
  6. Write it as a CLI script and use a CRON job to run it as frequently as required
  7. Then try running it when it isn't December or before 6am.
  8. 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) ;
  9. 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"];
  10. 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));
  11. 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); }
  12. @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
  13. 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
  14. 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 | +--------+---------+---------+-----------+-----------+----------+
  15. Look at the results from your first query. How many rows are returned? How many fetches do you perform?
  16. 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'); }
  17. use usort() with a callback function which converts the first 10 chars of each line to yyyy-mm-dd format and compares them.
  18. 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>
  19. This section of code now works. I have highlighted the two places where I made corrections.
  20. As far as I know, <?php always required whitespace after it.
  21. Because it first checks the code for valid syntax before it excutes the code. Syntax errors it does find are "startup errors"
  22. I'd start by changing all incidences of <?php} to <?php } ( ie Leave a space after <?php)
  23. Give us a clue - what is the error message?
  24. 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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.