EdgarsK Posted May 4, 2010 Report Share Posted May 4, 2010 Sveiki, ir tabula kurā tiek glabāti dati statistikas attēlošanai. Statistikas saņemšana if($type != 'user' && $type != 'web') $type=false; $results = array(); $db = Database_::query("select * from method_rstats where ".($type?"method='{$type}' and ":"")."project_id='{$project}' order by id desc"); if($db->num_rows()){ foreach($db->result() as $row){ $date = getTime($row->created,false); $type = $row->method; if(!isset($results[$date])) $results[$date] = (object)array('user'=>0,'web'=>0); $results[$date]->$type++; } } return $results; gala rezultātā man ir masīvs kurā ir šādi dati array( '21. Jun' => array('user'=>52,'web'=>631), '22. Jun' => array('user'=>52,'web'=>631), '23. Jun' => array('user'=>52,'web'=>631), '24. Jun' => array('user'=>52,'web'=>631), '25. Jun' => array('user'=>52,'web'=>631), '26. Jun' => array('user'=>52,'web'=>631), .... ) problēma: dati ir pārāk daudz, php kods atmirst pirms masīvs ir izveidots. Kā izvilkt datus tā, lai netiktu pārslogots php/sql Teiksim, select count(id) from tabula where datumi_nav_vienadi Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted May 4, 2010 Report Share Posted May 4, 2010 Teiksim, select count(id) from tabula where datumi_nav_vienadi kautkaa saadi SELECT DISTINCT datums, count(*) FROM tabulis GROUP BY datums ORDER BY id DESC GROUP BY nepieciesams obligati, jo pec shii tiks sagrupeeti tie ieraksti DISTINCT --> UNIKALS ( tas ir tikai tie kas netkartojas -- tikai aceries ka datums buus UNIKALS , ja saglabaa arii pulkstenlaiku, tad tas arii tiks njemts veraa.. taatad jaizmanto SQL datuma funkcijas lai atlasiitu tikai GADU,MENESI DATUMU ... -- Bet nu jebkura gadijuma konstrukcijas DISTINCT kop ar GROUP BY P.S. iesaku sql pieprasijumos komandas rakstiit ar Lielajiem simboliem --> krietni parskatamak Quote Link to comment Share on other sites More sharing options...
php newbie Posted May 5, 2010 Report Share Posted May 5, 2010 kautkaa saadi SELECT DISTINCT datums, count(*) FROM tabulis GROUP BY datums ORDER BY id DESC GROUP BY nepieciesams obligati, jo pec shii tiks sagrupeeti tie ieraksti DISTINCT --> UNIKALS ( tas ir tikai tie kas netkartojas -- tikai aceries ka datums buus UNIKALS , ja saglabaa arii pulkstenlaiku, tad tas arii tiks njemts veraa.. taatad jaizmanto SQL datuma funkcijas lai atlasiitu tikai GADU,MENESI DATUMU ... -- Bet nu jebkura gadijuma konstrukcijas DISTINCT kop ar GROUP BY P.S. iesaku sql pieprasijumos komandas rakstiit ar Lielajiem simboliem --> krietni parskatamak ja jau dati tiek sagrupēti pēc datuma, priekš kam DISTINCT ? Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted May 5, 2010 Report Share Posted May 5, 2010 ja jau dati tiek sagrupēti pēc datuma, priekš kam DISTINCT ? nu jaa var bez shamaa, vienkarshi kaa piemeru, ja nevajadzetu skaitu, bet tikai unikalos.. tad attiecigi varetu bez GROUP BY ... piedevam varbutm, pec tam, grib izmantot vel kadu Unikalu vertibu ... tapec piemera uzrakstiju... nav jau jaizmanto 100% kaa uzrakstiits, bet gan japielago savam vajadzibam .. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.