Use primary row as noimage.png vs checking with php

I have one simple question.

What is better. To put in table a field primary as noimage.png or to use empty fields and checking with php if field is empty and than assigning value of $image to noimage.png?

And is it better to use for such example null or not null?

Thank you

I’d personally use null in the database, it’d make more sense. Otherwise you’re associating noimage.png with everything without an image, so technically it has an image associated which isn’t actually relevant to the data.

It also allows you to associate various images with PHP:

//query and then:
while($Row = MySQL_Fetch_Assoc($Query)){
    if(strlen($Row['Image']) < 1){
        $Row['Image'] = 'noimage.png';
    }else if(!file_exists('images/' . $Row['Image'])){
        $Row['Image'] = 'notfound.png';
    }
}

And if you’re feeling adventurous, you could assign (for example) a category with an image - then any child to that category without an image uses that image!


SELECT
    A.ID,
    A.Title,
    IF(A.Image = '', C.Image, A.Image) As Img,
    A.Content
FROM
        Articles A
    INNER JOIN
        Categories C
    ON
        C.ID = A.Category

I’m not sure if my syntax is correct there, but it should make sense :slight_smile: