数据库表名称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;
}
我怎样才能做到这一点?感谢你的回答..
您应该使用fetch,例如fetch(PDO :: FETCH_ASSOC);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo $row['class'];
echo $row['date'];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句