Getting NULLs confused
Posted: Fri Feb 06, 2009 2:08 pm
Hello all.
Having a problem with my SQL->PHP code - bascially, I want the player name inserted in the first null player value (player1-4).
I'm using the code below, but $use is always null, not slot1-4 as I expected.
I've also tried using:
And also tried setting $player1-4 outside of the if, like this:
However, none seem to work.
I was thinking that an SQL null is different to a PHP null, as some people on the PHP manual seem to be suggesting, but I don't know how change it... even if I changed the query to ignore null values I wouldn't know which ones were null, which is what I need to know.
Any suggestions appreciated! I'm not that great at PHP, so examples are very useful ;P
Thanks.
Having a problem with my SQL->PHP code - bascially, I want the player name inserted in the first null player value (player1-4).
I'm using the code below, but $use is always null, not slot1-4 as I expected.
Code: Select all
function playerJoinRoom($username, $roomid)
{
// find the next NULL value in the $roomid and current players
$query = mysql_query("SELECT `room_id`, `current_players`, `player1`, `player2`, `player3`, `player4` FROM `room_list` WHERE `room_id` = $roomid");
$row = mysql_fetch_assoc($query);
$cp_before = $row['current_players'];
if (is_null($row['player1'])):
$use == 'slot1';
elseif (is_null($row['player2'])):
$use == 'slot2';
elseif (is_null($row['player3'])):
$use == 'slot3';
elseif (is_null($row['player4'])):
$use == 'slot4';
else:
$error == 'Clould not choose slot.';
endif;
// etc.
}
Code: Select all
if ($row['player1'] === null) {
$use == 'slot1';
} // etc.
Code: Select all
$player1 = $row['player1'];
if ($player1 === null) {
$use == 'slot1';
} // etc.
I was thinking that an SQL null is different to a PHP null, as some people on the PHP manual seem to be suggesting, but I don't know how change it... even if I changed the query to ignore null values I wouldn't know which ones were null, which is what I need to know.
Any suggestions appreciated! I'm not that great at PHP, so examples are very useful ;P
Thanks.