PHP - Display image based on record id

JohnMac328
JohnMac328 used Ask the Experts™
on
I am working with an example and trying to change it up some.  This code lists the records in the table. I am trying to add the image associated with each record in the list of all the records.  Here is the list of records

<?php
                   if($result = $mysqli->query($query)){
				       $no = 1;
                        while($row = $result->fetch_assoc()){
						  echo "<tr>
						         <td>$no</td>
						         <td><a href='student_info.php?s_id=".$row['s_id']."'>".$row['name']."</a></td>
						         <td>".$row['class']."</td>
                                
						       </tr>"
							   ;
						   $no++;	   
						}
                     } 
                ?>

Open in new window


Here is the code that dispalys the image based on the record id - I can't get the syntax to work with the previous code that is listing the records

<img src="<?php echo $row['s_img']; ?>" width="102" height="111"/>

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Expert of the Year 2014
Top Expert 2014

Commented:
I'm guessing you need to append the id with the extension at least? And maybe prepend it with the path maybe?

<img src="<?php echo $row['s_img']; ?>.jpg" width="102" height="111"/>

Author

Commented:
No that didn't work
Expert of the Year 2014
Top Expert 2014

Commented:
Didn't work doesn't really tell me anything
How are the images named? Where are they in relation to the script?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
This code
<img src="<?php echo $row['s_img']; ?>" width="102" height="111"/>

works on another page that is displaying one record - I want it to display on the page that is just listing the records in the table - as the image shows it displays the records - how to add the image associated with the student?
example.jpg
Expert of the Year 2014
Top Expert 2014

Commented:
Then it is probably the path that is incorrect, are the two php pages in the same folder?

Author

Commented:
Yes
Expert of the Year 2014
Top Expert 2014
Commented:
Do you actually have the code in the loop?

...
<td>".$row['class']."</td>
<td><img src='".$row['s_img']."' width='102' height='111'/></td>
...

Author

Commented:
That is what I needed - what you posted earlier

<img src="<?php echo $row['s_img']; ?>.jpg" width="102" height="111"/>

Did not work

Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial