Page 1 of 1

Reveal

Posted: Thu Dec 03, 2015 10:19 pm
by SpiritWebb
Alright, have another issue I have been trying to tackle for a while now. I have a table called explored_univ. Whenever a player enters a sector it updates this table showing where they been.

Now on my map page, I have a ton of ?'s listed as unexplored space to that player. I have the following code at the top of the page (yes I know, its mysql and not mysqli or PDO)

Code: Select all

$sql_pl = mysql_query("SELECT username, sect_start, sector FROM players WHERE email='$email'");
$sql_pl1 = mysql_fetch_array($sql_pl) or die("Cannot get sector");

$pl_username = $sql_pl1['username'];
$sect_start = $sql_pl1['sect_start'];
$sector = $sql_pl1['sector'];

$sql_map = mysql_query("SELECT sector_id, player_name, explored FROM explored_univ WHERE player_name='$pl_username'");
              $sql_map1 = mysql_fetch_array($sql_map) or die("Cannot get info");

              $sect_id = $sql_map1['id'];
              $map_sect = $sql_map1['sector_id'];
              $pl_user = $sql_map1['player_name'];
              $map_exp = $sql_map1['explored'];
I have this code where each question mark is located

Code: Select all

if($map_sect == '2' AND $pl_user == $pl_username AND $map_exp == 'Y')
{
  echo "P";
} else {
  echo "?";
}
So the bottom code is to match the sector number, username and explored in the explored_univ table. However all it is doing is pulling the very first record it comes to with that username and explored and not matching the '2', but in the table it shows I have been to sector 2. I cannot figure out why it will not work. Each sector is different and does not always show a "P". The P represents a planet, where "O" is open space, etc. Just at this sector there is a planet. Any suggestions?

Re: Reveal

Posted: Thu Dec 03, 2015 10:42 pm
by KyleMassacre
Its retrieving the first record only because you are not looping:

Code: Select all

$sect_id = "";
$map_sect = "";
$pl_user = "";
$map_exp = "";
while($sql_map1 = mysql_fetch_array($sql_map)) {
   $sect_id = $sql_map1['id'];
   $map_sect = $sql_map1['sector_id'];
   $pl_user = $sql_map1['player_name'];
   $map_exp = $sql_map1['explored'];
}
if($map_sect == '2' AND $pl_user == $pl_username AND $map_exp == 'Y')
{
  echo "P";
} else {
  echo "?";
}
 

Re: Reveal

Posted: Thu Dec 03, 2015 10:47 pm
by KyleMassacre
I take it back. Let me get a proper look at the code and figure it out. I was in a rush because I had to clock out for work sorry

Re: Reveal

Posted: Thu Dec 03, 2015 11:15 pm
by SpiritWebb
KyleMassacre wrote:Its retrieving the first record only because you are not looping:

Code: Select all

$sect_id = "";
$map_sect = "";
$pl_user = "";
$map_exp = "";
while($sql_map1 = mysql_fetch_array($sql_map)) {
   $sect_id = $sql_map1['id'];
   $map_sect = $sql_map1['sector_id'];
   $pl_user = $sql_map1['player_name'];
   $map_exp = $sql_map1['explored'];
}
if($map_sect == '2' AND $pl_user == $pl_username AND $map_exp == 'Y')
{
  echo "P";
} else {
  echo "?";
}
  
I tried that before, thinking that was it and didn't work.
KyleMassacre wrote:I take it back. Let me get a proper look at the code and figure it out. I was in a rush because I had to clock out for work sorry
No worries

Re: Reveal

Posted: Thu Dec 03, 2015 11:28 pm
by KyleMassacre
This may sound silly but have you tried removing the quotes around the 2? Unless of course the data type in your table is set to a string

Re: Reveal

Posted: Thu Dec 03, 2015 11:32 pm
by SpiritWebb
KyleMassacre wrote:This may sound silly but have you tried removing the quotes around the 2? Unless of course the data type in your table is set to a string
It is set as INT(11) in the database, but tried it without the quotes anyway, and still nothing

Re: Reveal

Posted: Thu Dec 03, 2015 11:47 pm
by KyleMassacre
do a print_r or var_dump on $sql_map1 and see what it prints out

Re: Reveal

Posted: Fri Dec 04, 2015 12:35 am
by SpiritWebb
KyleMassacre wrote:do a print_r or var_dump on $sql_map1 and see what it prints out
Print_R result:
Array ( [0] => 1 [sector_id] => 1 [1] => SpiritWebb [player_name] => SpiritWebb [2] => Y [explored] => Y )

Re: Reveal

Posted: Fri Dec 04, 2015 1:47 am
by KyleMassacre
You are definitely going to have to loop it.

Code: Select all

$data = array();
while($sql_map1 = mysql_fetch_array($sql_map)) {
   $data[]  = array(
        'id' => $sql_map1['id'], 
        'sector_id' => $sql_map1['sector_id'], 
        'player_name' => $sql_map1['player_name'], 
        'explored' => $sql_map1['explored']
    );
}
var_dump($data);
What does that look like?

Re: Reveal

Posted: Fri Dec 04, 2015 5:43 am
by SpiritWebb
KyleMassacre wrote:You are definitely going to have to loop it.

Code: Select all

$data = array();
while($sql_map1 = mysql_fetch_array($sql_map)) {
   $data[]  = array(
        'id' => $sql_map1['id'], 
        'sector_id' => $sql_map1['sector_id'], 
        'player_name' => $sql_map1['player_name'], 
        'explored' => $sql_map1['explored']
    );
}
var_dump($data);
What does that look like?

Code: Select all

 	array(4) { [0]=> array(4) { ["sect_id"]=> NULL ["map_sect"]=> string(1) "1" ["pl_user"]=> string(10) "SpiritWebb" ["map_exp"]=> string(1) "Y" } [1]=> array(4) { ["sect_id"]=> NULL ["map_sect"]=> string(1) "2" ["pl_user"]=> string(10) "SpiritWebb" ["map_exp"]=> string(1) "Y" } [2]=> array(4) { ["sect_id"]=> NULL ["map_sect"]=> string(2) "12" ["pl_user"]=> string(10) "SpiritWebb" ["map_exp"]=> string(1) "Y" } [3]=> array(4) { ["sect_id"]=> NULL ["map_sect"]=> string(2) "45" ["pl_user"]=> string(10) "SpiritWebb" ["map_exp"]=> string(1) "Y" } }