1

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

5
  • 1
    I believe $row['projects.ProjectLink'] should be -> $row['ProjectLink'] and same with the other $row's Commented Mar 23, 2013 at 1:29
  • It would not work because I am using two tables instead of one Commented Mar 23, 2013 at 1:31
  • For the query use projects.foo and the echoing use what is after the . if that don't work add projects.ProjectLink AS 'ProjectLink' to your query and use the example I stated earlier. Commented Mar 23, 2013 at 1:35
  • 1
    An SQL result set consists of a single set of columns, regardless of which tables they originated in. By default, the columns in the result set will be named after the columns in the underlying tables (but not named after the tables themselves); you can name them explicitly using the AS keyword. In other words SELECT projects.ProjectLink ... is the same as SELECT projects.ProjectLink AS ProjectLink .... Commented Mar 23, 2013 at 1:35
  • 1
    print_r($row) and you know what you get Commented Mar 23, 2013 at 1:35

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

They can have arbitrary text, that's why they're quoted.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.