Good Morning.
I've been slowly working on a game I've had in mind for some time. Figured I better get on it before senility sets in.. anyway....
What I've run into is an mysql query to return all players, I then compute the distance based on [x,y] coordinates, and dump into an array.
The Code:
$currentid = $_COOKIE['spacewarid'];
$getfleet = 'select * from players';
$dofleet = mysql_query($getfleet, $dbconnect);
echo '<div id="status-screen-sensors">';
$i = 0;
while ($ships = mysql_fetch_array($dofleet))
{
if ($ships['id'] != $currentid)
{
$currentdistance = round(sqrt( pow(($ships['pos_x'] - $row['pos_x']),2) + pow(($ships['pos_y'] - $row['pos_y']),2)),2);
$currentships = array ( $i => array("Ship Name" => $ships['ship_name'], "Distance" => $currentdistance),
);
}
$i++;
print_r($currentships);
}
echo '</div>';
The print_r output to check the array data (prettied up for ease of reading):
Array ( - => Array ( [Ship Name] => Corn Cob [Distance] => 5.1 ) )
Array ( [1] => Array ( [Ship Name] => Golden Kronar [Distance] => 4.47 ) )
Array ( [1] => Array ( [Ship Name] => Golden Kronar [Distance] => 4.47 ) )
Array ( [3] => Array ( [Ship Name] => Money [Distance] => 5.66 ) )
I have 4 records in the database. It is pulling one of them twice for some reason and dumping it into an array. I put in echos to separate out and the info for Golden Kronar dumps twice and the other two do not.
I'm pretty sure I'm missing something obvious here but after two days of staring at it I'm getting cross eyed.
Thanks for any help!
Rich