Reveal

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Reveal

Post 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?
Image

Image
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Reveal

Post 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 "?";
}
 
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Reveal

Post 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
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Reveal

Post 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
Image

Image
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Reveal

Post 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
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Reveal

Post 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
Image

Image
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Reveal

Post by KyleMassacre »

do a print_r or var_dump on $sql_map1 and see what it prints out
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Reveal

Post 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 )
Image

Image
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Reveal

Post 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?
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Reveal

Post 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" } }
Image

Image
Post Reply

Return to “Advanced Help and Support”