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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.