Link to home
Start Free TrialLog in
Avatar of JohnMac328
JohnMac328Flag for United States of America

asked on

PHP - Display image based on record id

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
Avatar of Gary
Gary
Flag of Ireland image

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"/>
Avatar of JohnMac328

ASKER

No that didn't work
Didn't work doesn't really tell me anything
How are the images named? Where are they in relation to the script?
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
Then it is probably the path that is incorrect, are the two php pages in the same folder?
Yes
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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