Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从上次查询Wordpress中获取行数_Php_Mysql_Wordpress - Fatal编程技术网

Php 从上次查询Wordpress中获取行数

Php 从上次查询Wordpress中获取行数,php,mysql,wordpress,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'

我在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'");
$query=(“选择wp\u posts.ID、wp\u term\u relationships.object\u ID
来自wp_的职位
在wp_posts.ID=wp_term_relationships.object_ID上左连接wp_term_关系
其中post_日期=“$then”
和post_status='publish');
现在,当我在phpmyadmin中生成这个查询时,它给出了以下输出 显示第0-5行(共6行,查询耗时0.0013秒)

我想显示行数I-e 6总计。。。 那么我必须使用什么函数来显示它呢?

$query=(“选择计数(*)、wp\u posts.ID、wp\u term\u relationships.object\u ID
$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'");
来自wp_的职位 在wp_posts.ID=wp_term_relationships.object_ID上左连接wp_term_关系 其中post_日期=“$then” 和post_status='publish');
如何运行查询?您是否使用
wpdb
?是的,我使用$wpdb->posts.ID等。。问题解决请看Ulvund的答案谢谢,非常感谢。。。我昨晚在做这段代码计数(*)的工作。。。