Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Different rules for NULL / NOT NULL

    I'm setting up a movies review site, and having a bit of a problem with the movie data part.

    When entering the movie information, each movie is assigned up to 2 directors. These are saved in the fields "director" and "director2". Most movies only have 1 director, so the director2 field would be set to null. This brings the problem....

    If a movie has one director, the info should be parsed out on the page as:
    Director: {DIRECTOR}
    However, if the movie has 2 directors, it should be:
    Director: {DIRECTOR} & {DIRECTOR2}

    The closest I've been able to get to a usable solution is changing the array, ie:

    "DIRECTOR" => $data['director'],
    "DIRECTOR2" => " & ".$data['director2'],

    However, this parses out as:

    Director: {DIRECTOR} &
    or
    Director: {DIRECTOR} & {DIRECTOR2}


    Basically, I want the & to be used if there is two directors, and not used if there's only one.

    On another board, a user told me to try this, but I get parse errors on the "if" line, and I think he was getting a bit sick of me bugging him, heh....

    $directors = array($data['director']);
    if (!empty($data['director2'])) {
    $directors[] = $data['director2'];
    }

    ..and in the array:
    "DIRECTORS" => implode(" & ",$directors),

    Any help would be MUCH appreciated.... thanks!

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i don't exactly understand why you need an array. And even if you need an array, you only need one element for the 'director(s)'. Which you can get like
    PHP Code:
    $directors $data['director'];
    if (
    strlen($data['director2'])>=1) { 
       
    $directors .= ' & ' $data['director2'];

    $directors can now be stored inside an array
    If you store them in seperate alement, then you'll also need more code to proces the array and display the content
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    THANK YOU!

    That seemingly little thing has been bugging me for a good couple of days, heh.

    I use arrays for the templating class I use. Each part of the info is sent to an array, then parsed into seperate html files... ie, in a seperate html file for showing movies, a simple {DIRECTORS} calls up the info and puts it wherever it's called from.

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're welcome. It's always these litle things that can keep you bussy...
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

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