I have working on a mySQL search and then display the information accordingly within my PHP code to display it into my website however what I try to do so I get no results displayed. Before the code worked when I was only working with one table but when executing a join it would not work. I feel like I am not doing this correctly anymore and have searched for an answer but to no dismay. Here is the entire MySQL and PHP code at work and the error I get when I used both ini_set('display_errors','On') and the 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>
";
}
One of the error is
Notice: Undefined index: projects.ProjectLink in /home/a3027546/public_html/images/fanart.php on line 43
I don't believe array names can have a .
(dot) in them (or it could just be that the array being fetched doesn't include the table.
prefix) and causing a error in your code:
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']
}
should be:
while($row = mysqli_fetch_array($result)) {
echo $row['ProjectLink'] ...
$row['ProjectName'] ...
$row['ProjectDescription'] ...
(int)$row['EntryNum'] ...
(int)$row['Votes'] ...
$row['Update'] ...
$row['ProjectLogo']
}
If that doesn't work add something like projects.ProjectLink AS 'ProjectLink'
to each of your select items and use the above solution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.