Jump to content

[SOLVED] Can I open an image this way?


Joefunkx

Recommended Posts

I am using php to perform a query on a mysql table and then display the results on a page. Next to each result, i want to be able to display an image that pertains to that specific result. I do not want to upload the  images into the table due to space issues. Essentially, each result will have a 5 digit id variable that i am trying to name the images. So, for example, result a will have id 11111 so it would link to image 11111.jpg, result b will have id 22222, so it would link to image 22222.jpg. I tried the following without any luck-

 

<IMG SRC="<?yourfield?>.jpg">

 

where yourfield is equal to the 5 digit number mentioned above.. the only thing i get when the page is displayed is an empty image that is trying to point to ".jpg". Any thoughts on this? Thanks guys!

Link to comment
https://forums.phpfreaks.com/topic/56096-solved-can-i-open-an-image-this-way/
Share on other sites

Before trying to display your image, you need to debug your code/php to make sure you're pulling the value correctly from the database. You also need to make sure you're specifying the correct image path.

 

<?php

  $query = $db->query("SELECT * FROM usrinfo WHERE id = '$id'");
  $usrinfo = $db->fetch_array($query);

  echo'<img src="images/'.$usrinfo[uid].'jpg" alt="image info" />';

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.