Web Based Game: Echo Problem

Problems with echoing values from a multi-dimensional array

Page 1 of 1

2 Replies - 1222 Views - Last Post: 24 November 2007 - 08:23 AM Rate Topic: -----

#1 gachappan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-November 07

Web Based Game: Echo Problem

Posted 23 November 2007 - 04:08 PM

I'm creating a web-based game which is going pretty well, but I've managed to break my own code and can't see what I've done to make it go wrong. This code is for some start up questions. The users answer the questions at registration based on their character and they will gain certain stats which will affect how good they are at different aspects of the game.

The questions file I haven't included here because I haven't made any changes to that code. I did make some changes to this code though when I was adding some css to change the look of the page.

What I'd like help with is that the echos of the array aren't working to show what the users picked (a temporary part of the code so I can balanace out the stats properly). I can't understand why this is, and it's probably a case of me having been working on it all day and my brain is fried, but if someone could help me that'd be great because this is driving me mad.

<?
//here is where I include the questions file

$num_of_questions = 20;
$num_of_skills = 8;

if (isset($_POST['Go']))
{
	$skills = array(0,0,0,0,0,0,0,0,0);

	for ($i = 1; $i <= $num_of_questions; $i++)
	{
		if ($_POST['q'][$i] > count($qs[$i][answers]) || $_POST['q'][$i] < 1)
		{
			$errmsgs[] = 'Answer all the questions, dumbass.';
			break;
		}
		else
		{
			$answer = &$_POST['q'][$i];
			for ($s = 0; $s <= $num_of_skills; $s++)
			{
				$skills[$s] += $qs[$i][answers][$answer][skills][$s];
			}
		}
	}
	$clans = array(
	  '1' => $skills[clan1],
	  '2' => $skills[clan2],
	  '3' => $skills[clan3],
	  '4' => $skills[clan4],
	);
	$clan1 = $skills[clan1];
	$clan2 = $skills[clan2];
	$clan3 = $skills[clan3];
	$clan4 = $skills[clan4];
	$highest= key(array_fill_keys(array_keys($clans, max($clans)), max($clans)));
	$memory = $skills[memory];
	$physical = $skills[physical];
	$reflexes = $skills[reflexes];
	$wethic = $skills[wethic];
	$charisma = $skills[charisma];
	echo "<br>clan1: ".$clan1;
	echo "<br>clan2: ".$clan2;
	echo "<br>clan3: ".$clan3;
	echo "<br>clan4: ".$clan4;
	echo "<br>Clan: ".$highest;
	echo "<br>memory: ".$memory;
	echo "<br>physical: ".$physical;
	echo "<br>reflexes: ".$reflexes;
	echo "<br>wethic: ".$wethic;
	echo "<br>charisma: ".$charisma;

}

echo '<form method="POST" action="startup.php">';
echo '<table border="0" cellpadding="4" cellspacing="1" width="100%">
		<tr>
			   <td colspan="2" style="text-align: center;"><strong>Answer these</strong></td>
			</tr>';

for ($i = 1; $i <= $num_of_questions; $i++)
{
	echo '<tr>
			<td colspan="2"><strong>'.$qs[$i][answer].'</strong></td>
		</tr>';
	for ($q = 1; $q <= $qs[$i][num]; $q++)
	{
		echo '<tr>
			<td>'.$qs[$i][answers][$q][0].'</td>
			<td><input name="q['.$i.']" value="'.$q.'" type="radio" /></td>
		</tr>
		<tr>
			<td><hr></td>
		</tr>';
	}
}

echo '</table>';
echo '<input type="submit" value="Go" name="submit"></form>';


?>



Is This A Good Question/Topic? 0
  • +

Replies To: Web Based Game: Echo Problem

#2 nav33n  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 71
  • Joined: 02-October 07

Re: Web Based Game: Echo Problem

Posted 23 November 2007 - 09:39 PM

Quote

if (isset($_POST['Go']))
{


This has to be $_POST['submit'] since the submit button's name is "submit". If that doesn't fix your problem, then you have to show us the whole code.

Cheers.
Nav
Was This Post Helpful? 0
  • +
  • -

#3 gachappan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-November 07

Re: Web Based Game: Echo Problem

Posted 24 November 2007 - 08:23 AM

View Postnav33n, on 23 Nov, 2007 - 09:39 PM, said:

Quote

if (isset($_POST['Go']))
{


This has to be $_POST['submit'] since the submit button's name is "submit". If that doesn't fix your problem, then you have to show us the whole code.

Cheers.
Nav


That worked!

Thanks very much for your help Nav, I do feel like a big arse though because it was so simple >.<
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1