npsari Posted April 8, 2007 Share Posted April 8, 2007 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) Quote Link to comment Share on other sites More sharing options...
Zaid Posted April 8, 2007 Share Posted April 8, 2007 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) Quote Link to comment Share on other sites More sharing options...
npsari Posted April 8, 2007 Author Share Posted April 8, 2007 Ohh, that is a great info So, if I entered "" where there is no Image what should I change the code to... if ($Image==none) { Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 or empty($image) Quote Link to comment Share on other sites More sharing options...
npsari Posted April 8, 2007 Author Share Posted April 8, 2007 or empty($image) Can you show me please where to put this one in my code I dont know where to put this part Quote Link to comment Share on other sites More sharing options...
dhimok Posted April 8, 2007 Share Posted April 8, 2007 if (empty($Image) || $Image == "") { echo ""; } Quote Link to comment Share on other sites More sharing options...
npsari Posted April 8, 2007 Author Share Posted April 8, 2007 if (empty($Image) || $Image == "") { echo ""; } So, there is no need for the Else bit? Quote Link to comment Share on other sites More sharing options...
dhimok Posted April 9, 2007 Share Posted April 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.