我正在尝试制作一个页面,用于查看大约有5个广告的用户广告,只显示1个,这是代码:
<?php
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$db = new PDO('mysql:host=localhost;dbname=test', 'root', '', $pdo_options);
$r = $db->query('SELECT id, inputid FROM ads WHERE inputid='.$_SESSION['log'].'');
echo '<ol>';
while($data = $r->fetch())
{
echo '<li><a href="adpage.php?id='.$data['id'].'">'.$adpage.'</a></li>';
$r->closeCursor();
}
echo '</ol>';
?>
感谢帮助
答案 0 :(得分:5)
while($data = $r->fetch())
{
echo '<li><a href="adpage.php?id='.$data['id'].'">'.$adpage.'</a></li>';
$r->closeCursor(); //<-- put this out of the loop
}
喜欢这个
while($data = $r->fetch())
{
echo '<li><a href="adpage.php?id='.$data['id'].'">'.$adpage.'</a></li>';
}
$r->closeCursor();