这是我所添加的代码,它只是说,误差警告:()提供的foreach无效参数
警告:()提供的foreach无效参数
<?php
include '../../config/Database.php';
$pdo = Database::connect();
$q = "select branch_add,branch_Address,branch_landNo , branch_email , Fname from db_thisurienterprice.tbl_employee , db_thisurienterprice.tbl_branch , db_thisurienterprice.tbl_login where employeeBranch = branch_ID and NIC = " .$_SESSION['username'] ."limit 1";
foreach ($pdo->query($q) as $row) {
echo '<label class="control-label">'.$row['Fname'].' </label> <br/>';
echo '<label class="control-label">'.$row['branch_add'].' </label> <br/>';
echo '<label class="control-label">'.$row['branch_Address'].' </label> <br/>';
echo '<label class="control-label">'.$row['branch_landNo'].' </label> <br/>';
echo '<label class="control-label">'.$row['branch_email'].' </label> <br/>';
}
Database::disconnect();
?>
但如果我在查询中删除“limit 1
”,这可以正常工作。但那次同样的记录重复了3次。什么似乎是这个问题?
您的SQL查询无效,这可能是造成问题。添加一些错误处理并预先检查退货。 –