Leaderboard
Popular Content
Showing content with the highest reputation on 01/02/2024 in all areas
-
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 | +------+--------+1 point
-
@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 output1 point
-
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'); }1 point
-
Try $expected = array( '1111', '2222', '2222', '3333' ); $received = array( '1111', '2222', '3333', '3333' ); $cExp = array_count_values($expected); $cRec = array_count_values($received); foreach (array_keys($cExp+$cRec) as $prod) { $e = $cExp[$prod] ?? 0; $r = $cRec[$prod] ?? 0; switch ($e <=>$r) { case -1: $check = 'Over'; break; case 0: $check = 'OK'; break; case 1: $check = 'Under'; break; } echo $prod . " Ordered: $e Received: $r - $check <br>"; } giving 1111 Ordered: 1 Received: 1 - OK 2222 Ordered: 2 Received: 1 - Under 3333 Ordered: 1 Received: 2 - Over1 point
This leaderboard is set to New York/GMT-05:00