php - 我的 Telegram 查询出了什么问题?

标签 php mysql telegram telegram-bot

public function createCityDialog() {

  $selectCity = "select name from telegramCity limit 6 offset 0";
  $result = mysqli_query($this->connection, $selectCity);

  while ($row = mysqli_fetch_assoc($result)) {
    /* 
    $this->buttons[] = [
      'text' => $row["name"]
    ];*/

    $this->buttons["text"] = $row["name"];
  }

  $this->telegramAPI->sendMessage($this->buttons, $this->chatID);
  $this->telegramAPI->api("sendMessage", [
    'chat_id' => $this->chatID,
    'text' => 'Виберіть місто',
    'reply_markup' => [
      'inline_keyboard' => [
        $this->buttons
      ]
    ]
  ]);
}

它返回一个空数组。我认为,这是我在没有内嵌按钮的情况下发送消息的主要原因。

最佳答案

查询失败,因为 namereserved MySQL keyword .

修复方法是将关键字括起来,如下所示:

$selectCity = "select `name` from telegramCity limit 6 offset 0";

还有一点是,如果有更多结果,则不会将其附加到数组中。

$this->buttons["text"][] = $row["name"];

您的注释代码也可以完成这项工作。

关于php - 我的 Telegram 查询出了什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49509618/

相关文章:

php - MySQL 和 PHP pdo 的奇怪行为,怎么了?

sql - 替换 MySQL 结果

c# - 上传多个文件时出现 TLSharp 错误

php - UTF8 读取波斯字符串为 ?在 MySQL 5.0 中

php - 如何在 php 中的 mysql 查询中获取有用的错误消息?

php - 使用 Mysql 和 php 正确计算税金

sql - 带有 GROUP BY 和零条目的 MySQL COUNT

php - 锁定远程目录但不锁定 URL

c++ - 将新字段添加到 C++ vector

c# - 如何在 Telegram Api 中订阅聊天更新?