Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP - Display image based on record id

Posted on 2014-02-27
8
Medium Priority
?
769 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

609 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