现在已经为此苦苦挣扎了几个小时。谁能指出我哪里出错了。
我得到 的第一个错误是:
Fatal error: Call to undefined method PDO::rowCount() in
pm_wall.php on line 8
Call Stack: 0.0000 643680 1. {main}()
index.php:0 0.0015 662904 2.
include('pm_wall.php')
index.php:117
我得到的第二个错误是:
Warning: Invalid argument supplied for foreach() in pm_wall.php on line 19
Call Stack:
0.0000 643296 1. {main}() index.php:0
0.0015 649864 2. include(index.php:117
我该如何解决这个问题?下面是我的代码:
$sql = "SELECT * from pm_msg";
$result = $pdo->query($sql);
if($pdo->rowCount() > 0 && !empty($result)) // first error occurs here
{
foreach ($result as $row)
{
$user_id = $row['user_id'];
echo '<div id="content">
<div class="stbody">
<div class="stimg">';
// set profile picture
$sql = "SELECT img FROM pm_user WHERE id=$user_id";
$result = $pdo->query($sql);
foreach ($result as $row) // second error occurs here
{
echo $row['img'];
}
echo '<div id="stexpandbox"><div></div>';
echo '</div></div></div></div>';
}
}
else
{
echo 'Wanna be starting soemthing?';
}