gpt4 book ai didi

php - 无法显示查询结果

转载 作者:可可西里 更新时间:2023-11-01 07:39:37 26 4
gpt4 key购买 nike

我的查询在下面工作,但我无法显示应该为“2”的结果(非重复计数的结果)。相反,我得到“作者总数:ID”

//var_dump Result:

array(1) {
[0]=> object(stdClass)#349 (1) {
["COUNT(DISTINCT writing.ID)"]=> string(1) “2″
}
}

//Code:

$authors = $wpdb->get_results("SELECT COUNT(DISTINCT writing.ID)
FROM writing
LEFT JOIN stories on writing.SID = stories.SID
LEFT JOIN wp_users ON writing.ID = wp_users.ID
WHERE (stories.SID = $the_SID)"
);

echo var_dump($authors);
print "Total Authors:" .$authors[0]->writing.ID ."<p>";

最佳答案

正如您从 var_dump 的输出中看到的,您需要的值被存储为对象的成员 COUNT(DISTINCT writing.ID)。您可以遵循一些解决方法。

  1. 将索引存储为单独的变量,然后在打印时使用它。

    $t = "COUNT(DISTINCT writing.ID)";
    print "Total Authors:" .$authors[0]->$t . "<p>";
  2. 在 MySQL 查询中使用别名。

    SELECT COUNT(DISTINCT writing.ID) AS writingID
    FROM writing
    LEFT JOIN stories ON writing.SID = stories.SID
    LEFT JOIN wp_users ON writing.ID = wp_users.ID
    WHERE (stories.SID = $the_SID)

    然后,

    print "Total Authors:" .$authors[0]->writingID . "<p>";

关于php - 无法显示查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25276792/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com