php/mysql phpmydamin服务器差异[已关闭]

fnatzsnv  于 2023-01-24  发布在  PHP
关注(0)|答案(1)|浏览(93)

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
23小时前关门了。
Improve this question
好的,我使用下面的查询

SELECT
    `inquiry_source`.`source` AS 'Source',
    `inquiry_source`.`colour` AS 'Colour',
    SUM(
        CASE WHEN `inquiry_source`.`source` = `customer_migration_details`.`Acquisition_Source` THEN 1 ELSE 0
        END
    ) AS 'count'
FROM  `inquiry_source`
    JOIN `customer_migration_details` 
            ON `customer_migration_details`.`Acquisition_Source` = `inquiry_source`.`source`
WHERE `date_opened` = '2023-01-23' AND `Acquisition_Source` != ''
GROUP BY `Acquisition_Source`

在phpMyAdmin中显示以下结果
| 来源|颜色|计数|
| - ------|- ------|- ------|
| 自动交易者|编号cc0099|1个|
| Ebay/电话|编号ffbb33|1个|
| 电子快照|编号00b3b3|1个|
| 脸书|编号0044cc|十一|
| 谷歌|编号ff6666|三个|
| 网络|编号668cff|十一|
然而当我来到php如下。

$sql= "SELECT
    `inquiry_source`.`source` AS 'Source',
    `inquiry_source`.`colour` AS 'Colour',
    SUM(
        CASE WHEN `inquiry_source`.`source` = `customer_migration_details`.`Acquisition_Source` THEN 1 ELSE 0
    END
    ) AS 'count'
FROM `inquiry_source`
    JOIN `customer_migration_details` 
        ON `customer_migration_details`.`Acquisition_Source` = `inquiry_source`.`source`
WHERE `date_opened` = '2023-01-23' AND `Acquisition_Source` != ''
GROUP BY `Acquisition_Source`";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
  while($row = $result->fetch_assoc()) {
    foreach($row as $k => $v){
      if($k == 'Source'){
        $seriesData[] = "'{$v}'";
      }
    }
  }

return implode(',', $seriesData);

它只返回以下内容(错过自动交易者)

Ebay/tel,
eShot,
FaceBook,
Google,
Web

我是不是错过了什么?
我试过改变查询,添加各种htmlentites()、htmlspecialchars()、addslashes()等,但都无济于事。

r7s23pms

r7s23pms1#

不确定为什么会缺少一行,但这是处理此过程的一种简单得多的方法

$result = $conn->query($sql);

while($row = $result->fetch_assoc()) {
    $seriesData[] = $row['source'];
}
return implode(',', $seriesData);

相关问题