PHP to output an HTML table but when it does the pictures refuses to display.

The php array $members['smallimg'] linkts to the .jpg file for example
[url]

// If there is at least 1 member listed as Faculty, then we are going to get the header and table set up and ready to display each member.
    if ($facultyfound == true)
    {
        $html .= '<h2><a name="faculty"></a>Faculty</h2>';

        $html .= '<tr>';
        $html .= '<th width="12%">Photo</th>';
        $html .= '<th width="11%">Name</th>';
        $html .= '<th width="9%">Title</th>';
        $html .= '<th width="14%">Contact</th>';
        $html .= '<th width="54%">Research</th>';

        $html .= '</tr>';

        for ($i = 0; $i < $size; $i++)
        {
            /*
                While we are looping through the for loop, we check each node to see if that node's information corresponds to the given department
                shortname and that the member is Faculty. If that is true, then we display the necessary information about them. If the XML element
                that normally contains information is actully empty, then it will just leave that space empty on the table as well in the corresponding
                position.
            */
            if ($members[$i]['department'] == $thedepartment && $members[$i]['facultytype'] == 'Faculty')
            {
                $html .= '<tr name="'.$members[$i]['shortname'].'">';
                $html .= '<td style="vertical-align: middle; text-align: center;"><a name="'.$members[$i]['shortname'].'"></a><img src="'.
                    $members[$i]['smallimg'].'" width="70" height="70"></td>';
                $html .= '<td style="vertical-align: middle; text-align: center;"><a href="'.$deptURL.'/faculty/faculty.php?name='.
                    $members[$i]['firstname'].' '.$members[$i]['lastname'].'">'.$members[$i]['firstname'].' '.$members[$i]['lastname'].', '.
                    $members[$i]['credentials'].'</a></td>';


                $html .= '<td style="vertical-align: middle; text-align: center;">'.$members[$i]['title'].'</td>';


                $html .= '</tr>';
            }
        }

    }

Dani AI

Generated

Brief diagnostic checklist and targeted fixes that build on and without repeating the original code.

First, confirm what the browser actually sees. Inspect the generated HTML (View Source) and copy the exact value of the image src attribute. Open that URL directly in a new tab and check the HTTP status. If the src contains any percent-encoded junk (for example %5B or %5D) or extra markup, it was likely introduced by string concatenation or a bad copy/paste and needs to be cleaned from the generated output.

Key checks to run:

  1. Confirm the final src (from view-source) points to the correct filename and that the server returns 200 for that exact URL.
  2. Use the browser DevTools Network tab to see if the image request returns 404/403/500 or a MIME/type warning.
  3. Verify filesystem issues: case sensitivity on Linux, file permissions, or hotlink protection.
  4. Prefer root-relative paths (e.g. /images/...) for same-site assets rather than embedding a full host name when possible. That avoids host mismatches and deployment issues.
  5. Ensure HTML is not being broken by unescaped quotes or nested tags — attributes should be escaped so the browser parses the img tag correctly.

Example server-side validation pattern (use this only as a safe check; adapt to the project):

$imageUrl = 'https://example.com/path/to/image.jpg';

if (@getimagesize($imageUrl)) {
    echo '<img src="' . htmlspecialchars($imageUrl, ENT_QUOTES, 'UTF-8') . '" alt="">';
} else {
    error_log('Missing image: ' . $imageUrl);
    echo '<img src="/images/placeholder.jpg" alt="no image">';
}

Useful references: MDN on the HTML img element (MDN img element), PHP getimagesize() (getimagesize()) and file_exists() (file_exists()). For runtime troubleshooting use the browser network docs (Chrome DevTools Network).

Recommended Answers

All 6 Replies

I could be wrong but it doesn't look like you have a picture extension at the end of your file name:

> $members[$i]['smallimg'].' 

it just has the . how is the browser to know what the file type is.
should be something like

<img src='$members[$1]['smallimg'].png' /> 

The php array $members['smallimg'] linkts to the .jpg file for example
[url]

maybe that's because it can't find the image.
anyway, when the links are to a page in the same webapp - deployed on the same server, providing a complete url (such as http:// .... ) may not be what you want to do. same goes for images

well I can't get your point try to be more clear...

@sheikhali what do you need clarification on?

what should i do instead?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.