Print Array if Condition Exists
<p>I'm working on a printing a baseball team lineup, via php. I want to print a place holder for a missing Player 6 (or any missing position) </p>

<p>So if Player 1 -> Player 5 is OK print, NO Player #6 print place holder, Player 7 -> Player 9 is OK print. I tried to simplify the code. I have tried solving this every which way but I keep getting stuck.</p>

<pre><code>CODE:

$rot        = array();
$pos        = array();
$jn             = array();

$x = 1;
// loads up the arrays from the db
while ( $rot[$x], $pos[$x], $jn[$x])= $r-&gt;fetch_row() ) {
$x++;
}

// counts the actual number of players in linuep
// used for validation and error display
$num_players = mysqli_num_rows($r);

// controls the lineup position
for ($i = 1; $i &lt;= 15; $i++){
    if($rot[$i] == $i) {
    //prints player             
$lineup .= "&lt;div data-fp='" . $pos[$i] . "'&gt;" .$jn[$i]. "&lt;/div&gt;";
    } else {
        // prints place holder
        $text = "This Position needs to be filled before the next game.";
        $lineup .= "&lt;div id='pid' data-rel='".$text."' data-fp='' data-pid='' data-jn='' title=''&gt;x&lt;/div&gt;";
    }
}
</code></pre>

<p>I also tried this to iterate through the array rot[] to find the matching position and print the line but it actually prints the holder repeatedly.</p>

<pre><code>// controls the lineup position
for ($x = 1; $x &lt;= 15; $x++){

for ($i = 1; $i &lt;= ($num_players+1); $i++) {
  if ($x == $i) {  
       //prints player              
        $lineup .= "&lt;div data-fp='" . $pos[$i] . "'&gt;" .$jn[$i]. "&lt;/div&gt;";
    } else {
        // prints place holder
        $text = "This Position needs to be filled before the next game.";
        $lineup .= "&lt;div id='pid' data-rel='".$text."' data-fp='' data-pid='' data-jn='' title=''&gt;x&lt;/div&gt;";
    }
  }
}
</code></pre>
