检查结果后无法显示语句结果 [英] Displaying statement result doesn't work after checking results
问题描述
我已经编写了一个代码来从数据库中选择数据,并且我测试了该语句是否使用fetchColumn()
返回了某项或否,如果使用fetch()
进行了循环,则显示了结果是否为null.但是,即使结果存在,它也不会显示任何内容.这是我的代码:
I've wrote a code to select data from my database, and I test if the statement returns something or no with fetchColumn()
and I display the results if it's not null using a loop with fetch()
. But event when the results exist it soesn't show me anything.. Here's my code :
$req = $bdd->prepare('SELECT NOM_Etudiant, PRENOM_Etudiant FROM Etudiant WHERE CNE_Etudiant = :cnev AND PASS_Etudiant = :passv');
$req->execute(array('cnev' => $cne, 'passv' => $pass));
$count = $req->fetchColumn();
if(!$count) {
header('Location: authentification_etud.php?status=invalid');
}
else {
// Doesn't work
while ($donnees = $req->fetch())
{
echo '<strong>Bienvenue </strong>' . $donnees['NOM_Etudiant'] . ' ' . $donnees['PRENOM_Etudiant'] . ' ! ' ;
}
}
您知道为什么它不起作用吗?谢谢:)
Do you know why it doesn't work ? Thank you :)
推荐答案
您应该使用rowCount()
方法来确定不是fetchColumn()
的行数. fetchColumn()
实际上会将指针移到结果集中,使您不再可以访问第一行数据.
You should use a rowCount()
method to determine the number of rows not fetchColumn()
. fetchColumn()
will actually advance the pointer in the result set to where you will no longer have access to the first row of data.
请注意此页面上的红色大警告 http://php.net/manual/zh/pdostatement.fetchcolumn.php
Notice the big red warning on this page http://php.net/manual/en/pdostatement.fetchcolumn.php
这篇关于检查结果后无法显示语句结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!