我正在进行mySQL搜索,然后在我的PHP代码中相应地显示信息,以便将其显示在我的网站中,但是我尝试这样做,所以没有显示任何结果。在代码工作之前我只使用一个表但是在执行连接时它不起作用。我觉得我不再正确地做这个了,并且已经找到了答案,但不要沮丧。以下是整个MySQL和PHP代码的工作以及我在使用ini_set('display_errors','On')和ini_set('error_reporting',E_ALL)时得到的错误;
$result = mysqli_query($connection, "SELECT
projects.ProjectName,
projects.ProjectLogo,
projects.ProjectLink,
projects.ProjectDescription,
entries.EntryNum,
entries.Votes,
entries.Views,
entries.Update
FROM projects
INNER JOIN entries
ON projects.ProjectID = entries.ProjectID
INNER JOIN
(
SELECT a.ProjectID, MAX(a.Update) max_val
FROM entries a
GROUP BY a.ProjectID
) b ON b.ProjectID = entries.ProjectID AND
b.max_val = entries.Update
WHERE projects.Media = 'image' AND
projects.Type = 'fan-art'
ORDER BY entries.Update DESC");
while($row = mysqli_fetch_array($result)) {
echo "
<a href=\"" . $row['projects.ProjectLink'] . "\" >
<div onMouseOver=\"description('" . $row['projects.ProjectName'] . "', '" . $row['projects.ProjectDescription'] . "', '" . (int)$row['entries.EntryNum'] . "', '" . (int)$row['entries.Votes'] . "', '" . $row['entries.Update'] . "', '" . "')\" style=\"width: 140px; height: 130px; float: left; margin: 0px 5px 5px 0px;\">
<img src=\"../" . $row['projects.ProjectLogo'] . "\" style=\"margin: 0px 5px 0px 5px;\" />
</div>
</a>
";
}
其中一个错误是
注意:未定义的索引:第43行/home/a3027546/public_html/images/fanart.php中的projects.ProjectLink
答案 0 :(得分:1)
我不相信数组名称中可能包含.
(点)(或者它可能只是被提取的数组不包含table.
前缀)并导致错误在你的代码中:
while($row = mysqli_fetch_array($result)) {
echo $row['projects.ProjectLink'] ...
$row['projects.ProjectName'] ...
$row['projects.ProjectDescription'] ...
(int)$row['entries.EntryNum'] ...
(int)$row['entries.Votes'] ...
$row['entries.Update'] ...
$row['projects.ProjectLogo']
}
应该是:
while($row = mysqli_fetch_array($result)) {
echo $row['ProjectLink'] ...
$row['ProjectName'] ...
$row['ProjectDescription'] ...
(int)$row['EntryNum'] ...
(int)$row['Votes'] ...
$row['Update'] ...
$row['ProjectLogo']
}
如果不起作用,请为每个选择项添加projects.ProjectLink AS 'ProjectLink'
之类的内容,并使用上述解决方案。