php - How to count the expected number of rows -


when have mysql query this:

select      i.`pk_faq_item`,      i.`title`,      i.`question`,      i.`featured`,      i.`published`,      date_format(i.`datecreated`, '%d-%m-%y %h:%i') `datecreated`,      date_format(i.`datechanged`, '%d-%m-%y %h:%i') `datechanged`,      i.`creator`,      i.`userchanged`,      if(isnull(s.`vote`), 0,sum(s.`vote`)) `votes`,      if(isnull(s.`vote`), 0,count(*)) `seen` `faq_item` left join `faq_item_stats` s on i.`pk_faq_item` = s.`fk_faq_item` group i.`pk_faq_item` limit 0, 30 

how can know how many results there without limit 0, 30.

pseudo query:

select count( * )   `faq_item` left join  `faq_item_stats` s on i.`pk_faq_item` = s.`fk_faq_item`  group i.`pk_faq_item` 

this gives me list this:

  • 3
  • 1
  • 1
  • 1

etc.

but expecting this:

  • 137

my current solution in opinion bad programming practice:

$query = $db->query("      select          i.`pk_faq_item`,          i.`title`,          i.`question`,          i.`featured`,          i.`published`,          date_format(i.`datecreated`, '%d-%m-%y %h:%i') `datecreated`,          date_format(i.`datechanged`, '%d-%m-%y %h:%i') `datechanged`,          i.`creator`,          i.`userchanged`,          if(isnull(s.`vote`), 0,sum(s.`vote`)) `votes`,          if(isnull(s.`vote`), 0,count(*)) `seen`     `faq_item`     left join `faq_item_stats` s on i.`pk_faq_item` = s.`fk_faq_item`     group i.`pk_faq_item` ");  $totalrows = $query->rowcount();  $query = $db->query("      select          i.`pk_faq_item`,          i.`title`,          i.`question`,          i.`featured`,          i.`published`,          date_format(i.`datecreated`, '%d-%m-%y %h:%i') `datecreated`,          date_format(i.`datechanged`, '%d-%m-%y %h:%i') `datechanged`,          i.`creator`,          i.`userchanged`,          if(isnull(s.`vote`), 0,sum(s.`vote`)) `votes`,          if(isnull(s.`vote`), 0,count(*)) `seen`     `faq_item`     left join `faq_item_stats` s on i.`pk_faq_item` = s.`fk_faq_item`     group i.`pk_faq_item`     limit 0, 30 "); 

select * ints; +---+ | | +---+ | 0 | | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | +---+  select sql_calc_found_rows * ints limit 3; +---+ | | +---+ | 0 | | 1 | | 2 | +---+  select found_rows(); +--------------+ | found_rows() | +--------------+ |           10 | +--------------+ 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -