【问题标题】:How to get the specific value from mysql database using pdo fetch? [duplicate]如何使用 pdo fetch 从 mysql 数据库中获取特定值? [复制]
【发布时间】:2020-07-07 10:58:13
【问题描述】:

数据库表名userclass有此列:user, class, date

$stmt = $conn->prepare("SELECT * FROM userclass WHERE user = :user");
$stmt->bindValue(":user", "James");
$stmt->execute();

我想获取用户为“James”的班级和日期的值并使用 php 打印出来

for($i=0; $i< the amount of row in which the user is 'James'; $i++){
  echo the class from database;
  echo the date from database;
}

我该怎么做?谢谢你的回答。。

【问题讨论】:

    标签: php mysql pdo


    【解决方案1】:

    你应该使用 fetch 例如 fetch(PDO::FETCH_ASSOC);

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
      echo $row['class'];
      echo $row['date'];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      • 2013-08-29
      • 2020-11-16
      相关资源
      最近更新 更多