gpt4 book ai didi

php - 使用 fetchcolumn() while 循环在 pdo 中无法正常工作后

转载 作者:行者123 更新时间:2023-11-29 11:14:51 24 4
gpt4 key购买 nike

我是 PHP 新手,现在正在使用 PDO 来使我的网站更安全,但是当我使用 fetchcolumn() 时,while 循环无法正常工作。它不会返回所有行。

这是我的代码

$stmt = $pdo->prepare("SELECT * FROM impdate where joblink=? and status='y' order by id desc");
if ($stmt->execute(array($joblink))) {
$rows = $stmt->fetchColumn();
if ($rows == "") {
echo '<style type="text/css">.impdate{display: none;}</style>';
}else{
while ($row = $stmt->fetch()) {
echo'<tr><td>'.$row['title'].'</td> <td>'.$row['date'].'</td></tr>';
}
}
}

请帮帮我......

注意:当我删除 fetchcolumnl 并仅运行 while 循环时,它可以正常工作

最佳答案

试试这个

use $rows = $stmt->rowCount(); instead of $rows = $stmt->fetchColumn(); 

$rows = $stmt->fetchColumn();用于仅获取单行。

关于php - 使用 fetchcolumn() while 循环在 pdo 中无法正常工作后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39928545/

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