How would I do this?

Discussion in 'PHP' started by Althema, Jul 27, 2007.

  1. #1
    What code would I use to display text in the database, yet have it show default text if nothing is added to the database?

    Basically if a user signs up at my site and adds their code number for a CJ banner, then it shows their CJ banner on the posts they start on my blog.

    If they do not add a CJ number, then it shows my number, the default number.

    I have the program where the information is added to the database fine, and also it pulls added ID's fine, but if someone doesn't add an ID it really messes my banners up because there is no ID added to the banner code at all, so I would like it to add my number until they can add their own CJ number.

    I can program what I need, if someone can guide me to a tutorial or lesson that explains the coding concept. I just don't know where to begin.
     
    Althema, Jul 27, 2007 IP
  2. ZenOswyn

    ZenOswyn Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Where ever you use the code number to display a banner, do something like this.

    
    if( isset($codeNumber) {
       echo "Display normally";
    } else {
       echo "Display default";
    }
    
    Code (markup):
     
    ZenOswyn, Jul 27, 2007 IP
  3. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Doesn't a if() clause suffices?

    
    <?
    if(empty($cj_number))
    {
        $cj_number = "Default Number Here";
    }
    ?>
    
    PHP:
     
    DeViAnThans3, Jul 27, 2007 IP
  4. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you're using MySql, you can enter a default value on the database field in the table structure - there's no need to code anything.
     
    ecentricNick, Jul 28, 2007 IP
  5. Althema

    Althema Peon

    Messages:
    181
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks everyone!!!! I got it working, now I can dance a jig WOOOHOOOO

    I've been working on this for 10 hours straight and I was about to go ga ga.

    Thanks tons!!! It's working wonderfully for me now!!!!
     
    Althema, Jul 28, 2007 IP