Smart Developer Smart Developer - 10 months ago 47
MySQL Question

after use fetchcolumn() while loop is not working correctly in pdo

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

Answer Source

Try this

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

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