无法获得工作。未定义的索引! [英] Cant get foreach to work. Undefined index's!
本文介绍了无法获得工作。未定义的索引!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最近我一直在尝试使用PDO来提高安全性,我遇到了一个我无法解决的错误。我认为它可能与FetchAll()和/或foreach有关。
这是我的代码:
Hi,
Recently ive been trying to use PDO for better security and I've come across an error that I cant fix. I think it may be related to the FetchAll() and/or foreach.
This is my code:
$type = general;
$db = Database::getConnection();
$query = 'SELECT * FROM threads WHERE threadTopic=:threadTopic';
$output = $db->prepare($query);
$results = $output->execute(array(':threadTopic' => $type));
if (count($results) > 0) {
echo "<table class=\"discussion\">\n";
echo "<tr><th colspan=2>Thread Name</th><th>Replies</th><th>Author</th></tr>\n";
$rows = $output -> fetchAll();
$name = $rows['threadName'];
$body = $rows['threadBody'];
$by = $rows['threadBy'];
$date = $rows['dateCreated'];
$sticky = $rows['threadSticky'];
$image = '<img src="images/userIcon.gif"></img>';
foreach ($rows as $row){
echo "<tr>";
echo"<td>".$image."</td>";
echo"<td>".$name."<br>".$body."</td>";
}
echo "</tr>\n";
echo "</table>";
}
正在显示表格和表格标题但是foreach不起作用并且说我的变量来自计数都是未定义的。
求助?
The table and table headings are being displayed but the foreach is not working and is saying that my variables from the count are all undefined.
Help, please?
推荐答案
type = general;
type = general;
db = Database :: getConnection();
db = Database::getConnection();
query = ' SELECT * FROM threads WHERE threadTopic =:threadTopic';
query = 'SELECT * FROM threads WHERE threadTopic=:threadTopic';
这篇关于无法获得工作。未定义的索引!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文