使用fetchcolumn()之后while循环在pdo中无法正常工作(after use fetchcolumn() while loop is not working correctly in pdo)

我是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循环中运行时,它可以正常工作

I am new in PHP and I am using PDO right now for making my website more secure but when I use fetchcolumn() then the while loop is not working correctly. it does not return all row.

here is my code

$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>'; } } }

help me, please.....

Note : When I remove fetchcolumnl and run only while loop then it work correctly

最满意答案

尝试这个

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

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

Try this

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

$rows = $stmt->fetchColumn(); is used to get the single row only .

使用fetchcolumn()之后while循环在pdo中无法正常工作(after use fetchcolumn() while loop is not working correctly in pdo)

我是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循环中运行时,它可以正常工作

I am new in PHP and I am using PDO right now for making my website more secure but when I use fetchcolumn() then the while loop is not working correctly. it does not return all row.

here is my code

$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>'; } } }

help me, please.....

Note : When I remove fetchcolumnl and run only while loop then it work correctly

最满意答案

尝试这个

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

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

Try this

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

$rows = $stmt->fetchColumn(); is used to get the single row only .