doujia9833 2013-05-13 05:51
浏览 69
已采纳

Paginate问题与group by的查询中的count

Ok I usually use a pagination code that counts the total pages, like this

$query = "SELECT COUNT(*) as num FROM $tableName WHERE `ganador2` = '1'";
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages[num];

then i call the data with this query for echo page contents.

// Get page data
    $query1 = "SELECT id,name,lastname,email,codigo, media, phone, Pcode, birth FROM $tableName  WHERE `ganador2` = '1' LIMIT $start, $limit ";

this last part is the Working code, ok,

Know im trying to use it with this querys, this count how many times the user has entered his email.

$query = "SELECT COUNT(*) AS num,id,name,lastname,email,codigo, media, phone, Pcode, birth FROM usuarios GROUP BY email";
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages[num];

and

// Get page data
    $query1 = "SELECT COUNT(*) AS top,id,name,lastname,email,codigo, media, phone, Pcode, birth FROM usuarios GROUP BY email ORDER BY top DESC LIMIT $start, $limit";

The problem is for pagination, its telling me the query just found (2 users) but thats not true, so my query its wrong.. How can i calculate the total pages in the first query, as the second query is working just fine.

thanks

  • 写回答

4条回答 默认 最新

  • duanjiancong4860 2013-05-13 05:57
    关注

    with the group by you are getting a count per email. you are getting the number of records that have the first email... I think this is what you want.

    SELECT COUNT(DISTINCT email) AS num FROM usuarios;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题