View Full Version : Different rules for NULL / NOT NULL

03-28-2004, 05:11 AM
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} &
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!

03-28-2004, 10:37 AM
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

$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

03-28-2004, 12:15 PM

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.

03-28-2004, 12:52 PM
You're welcome. It's always these litle things that can keep you bussy...