Solved

PHP - Display image based on record id

Posted on 2014-02-27
8
753 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
 

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now