theoneweasel77
Programmer
I'm trying to add an element on to the end of a multi demensional array, which should end up as $games[$i][9]. The code below is included in my page.
and it is included in the following script using the document root. (the entire script is not listed below)
everything works fine, except that the color is not being passed\set in $games[$i][9], and is being acted upon as though it were another element in the first array level ($games[num]). Why is this?
output is at Also, I've tried using array_push(), but I can't get that to work since it's a multi-demensional array.
Code:
<?
function find_games($db, $username)
{
$games_in_progress = 0;
$result = mysql_query("select * from games where game_creator = '$username'", $db);
if (! $result)
$games_in_progress++;
else
{
$i = 0;
while (true)
{
$row = mysql_fetch_row($result);
if ($row)
$games[$i] = $row;
else
{
$games[$i][9] = "b";
break;
}
$i++;
}
}
$result = mysql_query("select * from games where game_partner = '$username'", $db);
if (! $result)
$games_in_progress++;
else
{
while (true)
{
$row = mysql_fetch_row($result);
if ($row)
$games[$i] = $row;
else
{
$games[$i][9] = "r";
break;
}
$i++;
}
}
if ($games_in_progress == 2)
$games = "You aren't playing any games yet";
return $games;
}
function games_check($db, $username)
{
$games = find_games($db, $username);
if (! is_array($games))
return "You are not playing any games";
else
return $games;
}
?>
Code:
<?
if ( ! $games[$i] )
{
print "<tr valign=center bgcolor=DDDDDD>";
print "<td align=left colspan=4>";
print "<b>You are not playing any games</b>";
}
{
while(true)
{
?>
<TR VALIGN=CENTER bgcolor=DDDDDD>
<TD ALIGN=LEFT>
<A HREF="in game source.php?ID=<? print $games[$i][4]; ?>&color=<? print $games[$i][9]; ?>">
<? print $games[$i][0]; ?>
</A>
<BR>
<SPAN CLASS=small_text_8>
Field Command
</SPAN>
</TD>
<TD ALIGN=CENTER>
<? print $games[$i][2]; ?>
</TD>
<TD ALIGN=LEFT>
<SPAN CLASS=small_text>
<? print $games[$i][5]; ?>
</SPAN>
<BR>
<SPAN CLASS=small_text>
<? print $games[$i][6]; ?>
</SPAN>
</TD>
<td align=left>
<?
if ( $games[$i][7] == "yes")
{
print $games[$i][1];
print "<br>";
}
if ( $games[$i][8] == "yes")
print $games[$i][2];
?>
</td>
<TD>
</TD>
<td>
</td>
</tr>
<?
$i++;
if ($games[$i] == 0)
break;
}
}
?>
output is at Also, I've tried using array_push(), but I can't get that to work since it's a multi-demensional array.