Jump to content

A problem with a little else function


npsari

Recommended Posts

I have a field which asks the user to insert an image URL

 

This field is called Image

 

The initial value of the field is 'none'

 

So, if the users leaves it like that, it is saved in the databse as none

but if he puts an URL, it is not saved as none (obviously!)

 

So, I did this display code...

 

 

while($row = mysql_fetch_array($result))

{

if ($Image==none) {
     print "No Image\n";
} else {
     print ("<IMG src=\"$row[image]\" alt=\"Image\" border=\"0\" ><BR><BR>\n");
}

 

Is this code fine?

 

Because an Image keeps showing (even the missing shape one) :(

Link to comment
Share on other sites

1) there is a missing "}" at the end of your code

2)if that doesn't work, depending on your original code where you enter the data into the db, if you entered "" when there is no image then that's not a null value, there is a difference between "" and null. so try changing ($Image==NULL)

Link to comment
Share on other sites

U can do it like this

 

while($row = mysql_fetch_array($result)) {

     if (empty($row[image]) || $row[image] == "") {
          print "No Image\n";
     } else {
          print "<img src=\"".$row[image]."\" alt=\"Image\" border=\"0\" >\n";
          //print '<img src="'.$row["Image"].'" alt="Image" border="0" />'; // <-- or like this
     }
} // end while

 

You can always use extract() or list() function to pull db fields into variables

 

while($row = mysql_fetch_array($result)) {
extract($row);

     if (empty($image) || $image == "") {
          print "No Image\n";
     } else {
          print "<img src=\"{$Image}\" alt=\"Image\" border=\"0\" >\n";
          //print '<img src="'.$Image.'" alt="Image" border="0" />'; // <-- or like this
     }
} // end while

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.