Jump to content
php.lv forumi

datu saņemšana


EdgarsK

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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 ..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...