php - MySQL Query problem in CodeIgniter -


so i'm using following:

    $r = new record();     $r->select('ip, count(*) ipcount');     $r->group_by('ip');     $r->order_by('ipcount', 'desc');     $r->limit(5);      $r->get();      foreach($r->all $record)     {         echo($record->ip." ");         echo($record->ipcount." <br />");     } 

standard:

select `ip`, count(*) ipcount (`soapi`) group `ip` order `ipcount` desc limit 5; 

and last (fifth) record echo'ed out , no ipcount echoed.

is there different way go around this? i'm working on learning datamapper (hence questions) , need figure of out. haven't quite wrapped head around whole orm thing.

is there way set count(*) ipcount without funny select() statement? don't think it's triggering reason. bug in datamapper, i'm less of that.

also found if use $r->query() method doesn't return except last entry if use selectipfromsoapiwhere 1;. return (like should) if select * soapi 1;. if doesn't have * returns last line.

just verified new query, except selecting columns (*) returns last record. great. can craft statement select *, count(*) ipcount still don't have access via $record->ipcount.

for case, once use count() function in mysql, return 1 value. hence ip result data not display out.

i suggest split 2 queries. 1. count(*) 2. ip

hope help.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -