tags:

views:

40

answers:

4

I not sure which one would use less execution time if the user is advertising a classifieds ad and did not upload any image, a 'blank.jpg' would replace the image in HTML code.

which is: <img src="blank.jpg">

For the PHP, I use if-conditional when read data from mysql and replace '0' value with 'blank.jpg', would it be optimal if the database just store 'blank.jpg' value instead of '0'?

+1  A: 

It probably won't make much difference to performance, but it does make a difference to data cleanliness. Null values should be stored as NULL.

The fact that you want to show "blank.jpg" is a display issue, not a data issue. If you want to use this data elsewhere, it'll be much more efficient to check for NULL than for "blank.jpg".

Dominic Rodger
Thanks all guys for the great advice.
proyb2
A: 

No, it's probably a better solution to do it in application code (PHP). That way the database can easily be used for more than one application, e.g., if you in the future rewrite the software or if you open other sites which you want to synchronize with this one.

Store a NULL in the database.

Emil Vikström
Thanks all guys for the great advice.
proyb2
A: 

leave the field in mysql as null and set the schema so that is default then there is no operation if there is no image. you can test for null rather than zero or anything else. or did i miss something

PurplePilot
A: 

If you can, store a 0 or empty string as opposed to storing a NULL value.

NULL columns require additional space in the row to record whether their values are NULL. For MyISAM tables, each NULL column takes one bit extra, rounded up to the nearest byte.

Chris