Solved

PHP - Display image based on record id

Posted on 2014-02-27
8
755 Views
Last Modified: 2014-02-27
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
0
Comment
Question by:JohnMac328
  • 4
  • 4
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39892269
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"/>
0
 

Author Comment

by:JohnMac328
ID: 39892274
No that didn't work
0
 
LVL 58

Expert Comment

by:Gary
ID: 39892294
Didn't work doesn't really tell me anything
How are the images named? Where are they in relation to the script?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:JohnMac328
ID: 39892306
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
0
 
LVL 58

Expert Comment

by:Gary
ID: 39892327
Then it is probably the path that is incorrect, are the two php pages in the same folder?
0
 

Author Comment

by:JohnMac328
ID: 39892329
Yes
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39892357
Do you actually have the code in the loop?

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

Author Closing Comment

by:JohnMac328
ID: 39892361
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
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question