Jump to content

[SOLVED] image not showing


kev wood

Recommended Posts

i have a CMS where the user has the option to upload an image to go with a news article.  i had the problem where if they decided not to upload an image ie would put a red cross where the image was supposed to be.

 

to work around this i tried to put an if statement in to stop the red cross if there was no image for that article.  but all i have managed to do is stop all images being displayed.

 

here is the code i have so far.

 

$result = mysql_query("SELECT * FROM news ORDER BY id DESC") or die(mysql_error());
	echo "<div style=\"height: 500px; width: 450px; overflow:auto;\">";
	echo "<table width=350px border=0>\n"; 
	// keeps getting the next row until there are no more to get
	while($row = mysql_fetch_array( $result )) {
		// Print out the contents of each row into a table
		echo "<tr><td>"; 
		echo $row['date'];
		echo "</td></tr>";
		echo "<tr><td><b>"; 
		echo $row['title'];
		echo "</b></td></tr>";
		echo "<tr><td>"; 
		if(!empty($row['image'])) {
		echo '<img src="images/'.$row['image'].'">'; 
		} 
		echo $row['article'];
		echo "</td></tr>";
		echo"<tr><td> </tr></td>"; 
	} 

Link to comment
https://forums.phpfreaks.com/topic/152371-solved-image-not-showing/
Share on other sites

Hi kev wood,

 

Change the portion

 

if(!empty($row['image'])) {
         echo '<img src="images/'.$row['image'].'">';
         } 

 

to

 

$imgurl = "images/".$row['image'];
if($row['image'] && file_exists($imgurl)) {
echo "<img src=$imgurl>";
}

 

let me know if the issue persists

 

 

Regards

Ranju

thanks again for the replies i have it working now with ranjuvs solution.

 

cs1h

 

your reply will probably be what i do in future.

 

Yesideez

 

i know it is a bit late to mention but yes the files name is held in the db and not the actual image its self.

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.