SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    Dilster.com - Dating blog where you can find new dating tips, advices and ideas or your partner.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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:

    PHP Code:
    //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!
    Code sql:
    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
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •