获取上次查询的行数,Wordpress

时间:2011-12-13 09:49:59

标签: php mysql wordpress

我正在使用wordpress平台,在生成mysql查询时,我想显示该查询的行数。示例如下所示。

$query = ("SELECT wp_posts.ID, wp_term_relationships.object_id
     FROM wp_posts
     LEFT JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id
     WHERE post_date <= '$now'
     AND term_taxonomy_id = '$catid'
     AND post_date >= '$then' 
     AND post_status = 'publish'");

现在,当我将此查询生成到phpmyadmin时,它会提供以下输出 显示行0 - 5(总共6行,查询耗时0.0013秒)

我想显示总行数i-e 6 ... 那么我必须使用什么功能才能显示它?

1 个答案:

答案 0 :(得分:0)

$query = ("SELECT count(*), wp_posts.ID, wp_term_relationships.object_id
 FROM wp_posts
 LEFT JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id
 WHERE post_date <= '$now'
 AND term_taxonomy_id = '$catid'
 AND post_date >= '$then' 
 AND post_status = 'publish'");