PHP - 在SQL中选择忽略NULL选择查询

I'm trying to pull a list of my actors via the foreign key stored in my main 'movies' table. It will work if all actor fields are populated, but will die if any one of those fields are NULL.

$stars = mysql_query("
    SELECT actor_name
    FROM actors
    WHERE actorID = $row[5] OR actorID = $row[6] OR actorID = $row[7] OR actorID = $row[8]  OR actorID = $row[9] OR actorID = $row[10]
")
or die("<h1>Error - (stars) the query could not be executed</h1>
");
$count = 0;
while ($row_stars = mysql_fetch_array($stars)) {
    print("$row_stars[0]<br/>
");
    if ($count == 2) {
        print("</td>
");
        print("<td>
");
    }
    $count++;
}
print("</td>
 </tr>
");

Whats the best way to handle this?

Cheers,

Sam

$actors = array_slice($row, 2, 6);
$actors_without_nulls = array_filter($actors, 'strlen');
$actorIds = implode(', ', $actors_without_nulls);

Now try,

SELECT actor_name
FROM actors
WHERE actorID IN ( actorIds )

Use the MySQL COALESCE() function

$stars = mysql_query("
    SELECT actor_name
    FROM actors
    WHERE actorID = COALESCE($row[5],$row[6],$row[7],$row[8],$row[9],$row[10],-1)
")