This topic is locked

need a default image in mysql

7/18/2007 4:47:54 PM
PHPRunner General questions
C
cgilpin author

Hi Everyone,

I have two mysql fields in my project to hold images (mediumblob). If there is no image then it displays the web broken image icon - i would like to be able to have a default image (which I have created) that is plain black with "waiting for image" in the middle. I know that mysql does not allow default values for blob. Any suggestions?
Thanks
Chris

J
Jane 7/19/2007

Chris,
you can do the following:

  1. place your default image to the output/images directory
  2. select Custom for your image field on the "View as" settings dialog on the Visual Editor tab and add your code in it.

    Here is a sample:
    global $data;

    if ($value)

    $value="<img border=0 src=\"TableName_imager.php?field=ImageFieldName&key1=".$data["PrimaryKey"]."\">";

    else

    $value = "<img border=0 src=\"images/your_filename.gif\">";



where ImageFieldName and PrimaryKey are your actual field name, TableName is your actual field name.