if(mysql_real_query(&m_pConnection->m_MySQL, szSQL, (UINT)szSQL.GetLength()) == 0)
                if((m_Result = mysql_use_result(&m_pConnection->m_MySQL)))
                {
                 ....
                  *m_ulCount = mysql_affected_rows(&m_pConnection->m_MySQL); //用返回查询总数则出错  增加,修改,删除有效果
                .....
               } mysql_query(&......)
 *m_ulCount = mysql_affected_rows(&m_pConnection->m_MySQL); //增加,修改,删除 后影响行数有效果1) 对查询结果集体一条一条累加算是没有问题 2)  用select count(*) as 算查询两次了, 还有啥办法好如何返回查询的总数?  谢谢大家了

解决方案 »

  1.   

    好多人做法是,写两条条件相同的语句   一条查询总数一条查询结果   
     select count(*)  from tab1 where name like 'aaa'; 
     
     select  * from tab1 where name like 'aaa' limit 0,10   还有别的办法吗?谢谢!
      

  2.   

    有些人讲"select sql_calc_found_rows * from DB_ACCOUNT" 一条能顶两条?到底行吗?
      

  3.   

    mysql_num_rows() 如何用?谢谢
      

  4.   


      szSQL = "select count(*) from DB_ACCOUNT";
      if(mysql_real_query(&m_pConnection->m_MySQL, szSQL, (UINT)szSQL.GetLength()) == 0)
            {                
                    if((m_Result = mysql_use_result(&m_pConnection->m_MySQL)))
                    {
                            m_ulCount = mysql_num_rows(m_Result);  //这句返回是0
                            .....
      

  5.   

    The use of mysql_num_rows() depends on whether you use mysql_store_result() or mysql_use_result() to return the result set. If you use mysql_store_result(), mysql_num_rows() may be called immediately. If you use mysql_use_result(), mysql_num_rows() does not return the correct value until all the rows in the result set have been retrieved. 
      

  6.   

    但在网上看到一段:
    mysql_num_rows 和 count( * ) 都能统计总数,那个能好一点呢?
    或者
    分别什么时候用num_rows 和 count( * )呢一个直观的对比
    测试数据:
    条数:139764条
    数据表大小:500M结果:
    fetch_num_rows 用时:35.272329092026
    count(*) 用时:0.071956872940063如果单纯统计数量 当然是count(*)
    fetch_num_rows必须遍历数据库以后才能得出 效率低于count(*) 不知道对否