我对自己做错了什么感到困惑。我已经在许多资源中查找了这一点,包括我正在学习 PHP 的书,它似乎应该是正确的......但它只是不起作用。
<?php
try
{
$sql = 'SELECT parks.id, parks.state, parks.name, parks.description, parks.site, parks.sname, parks.street, parks.city, parks.zip, parks.phone FROM parks
INNER JOIN comments ON parks.parkid = comments.parkid
INNER JOIN photos ON parks.parkid = photos.parkid
INNER JOIN events ON parks.parkid = events.parkid';
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching data: ' . $e->getMessage();
include 'output.html.php';
exit();
}
foreach ($result as $row)
{
$datas[] = array ('id' =>$row['id'],
'parkid' =>$row['parkid'],
'state' =>$row['state'],
'name' =>$row['name'],
'description' =>$row['description'],
'site' =>$row['site'],
'sname' =>$row['sname'],
'street' =>$row['street'],
'city' =>$row['city'],
'phone' =>$row['phone'],
'zip' =>$row['zip'],
'commentname' =>$row['commentname'],
'comment' =>$row['comment'],
'event' =>$row['event'],
'date' =>$row['date'],
'description2' =>$row['description2']);
}
include 'writing.html.php';
这将返回第一个表(公园)中的所有数据就好了。项目commentname、comment、event、date 和description2 来自连接表(events 和comments)
如果我回显 '$row['state']' 我会得到正确答案。但是,如果我回显其他表中的任何项目(例如 $row['comment']),我不会得到任何结果。
我错过了什么?