V
V
ViktorGuerro2018-09-24 01:47:54
PHP
ViktorGuerro, 2018-09-24 01:47:54

How to properly pull data from different mysql tables using ReadBeanPHP?

It seems to me that my code is unprofitable and if the data is large, it will take a long time to load, how best to format it?
5ba817e68a515477809687.png

include_once('/data/php/includes.php');
                        $cash = R::getAssoc('SELECT * FROM cash');
                        $terminal = R::getAssoc('SELECT * FROM terminal');
                        $online = R::getAssoc('SELECT * FROM online');
                        for ($i=30; $i>0; $i--) {
                           $date = date("Y-m-d", mktime(0, 0, 0, date('m'), date('d') - $i, date('Y')));

                              foreach ($cash as $cas) {
                                 if ( $date == $cas['date'] ) {
                                    $sum1 = $cas['money'];
                                    $j = 1;
                                 };
                              };
                              foreach ($terminal as $term) {
                                 if ( $date == $term['date'] ) {
                                    $sum2 = $term['money'];
                                    $j = 1;
                                 };
                              };

                              foreach ($online as $onli) {
                                 if ( $date == $onli['date'] ) {
                                    $sum3 = $onli['money'];
                                    $j = 1;
                                 };
                              };  

                        $sum = $sum1 + $sum2 + $sum3;

                        if ( $j == 1 ) {
                           echo $sum. ", ";
                           $j = 0;
                         } else {
                           echo "0,";
                         };
                         $sum1 = 0;
                         $sum2 = 0;
                         $sum3 = 0;
                        };

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question