flash/php highscore <HELP>

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
epiph
Forum Newbie
Posts: 2
Joined: Fri Mar 17, 2006 6:16 pm

flash/php highscore <HELP>

Post by epiph »

K i got this php script from a tutorial. And it doesnt work. the php error is

Code: Select all

Parse error: parse error, unexpected '}' in /home/vetgmed/public_html/zed/flash/scoreboard/scores.php on line 1
i looked in the file and there is no "}" on line one. can someone help

Thats the file: http://vet-media.com/zed/flash/scoreboard/scores.php
thats the flash: http://vet-media.com/zed/flash/scoreboa ... etable.swf
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mystery code please?
epiph
Forum Newbie
Posts: 2
Joined: Fri Mar 17, 2006 6:16 pm

Post by epiph »

Code: Select all

<?php

	$winscore = (int)$winscore;

	// Create a Blank File if it doesn't already exist
	if (!file_exists($filename))
	{
		$file=fopen($filename, "w");
		fclose ($file);
	}

	// Read the file in
	$oscores = file ($filename);
	$numreadin = count($oscores);

	// Break out the data into a new 2-d array called $tscores
	for ($i = 0; $i < $numreadin; $i++)
	{
		$g = unserialize($oscores[$i]);
		$tscores[$i][0] = $g[0];
		$tscores[$i][1] = $g[1];
	}

	// Fill in any missing data with none/0
	for ($i = $numreadin; $i < $scoresize; $i++)
	{
		$tscores[$i][0] = 0;
		$tscores[$i][1] = "";
	}

	// Process the actions	

	// Insert a score/name
	if ($action == "INSERT")
	{

		// Add name to end of list, and sort
		$tscores[$scoresize + 1][0] = $winscore;
		$tscores[$scoresize + 1][1] = $winname;
		rsort ($tscores);

		$file=fopen($filename, "w");

		// Write them out
		for ($i = 0; $i < $scoresize; $i++)
		{
			$st = serialize($tscores[$i]) . "\n";
			fputs($file, $st);
		}

		fclose($file);
	}

	// Clear the list	
	if ($action == "CLEAR")
	{

		$k[0] = 0;
		$k[1] = "no-one";
		$ser = serialize($k);

		$file=fopen($filename, "w");

		for ($i = 0; $i < $scoresize; $i++)
		{
			$st = $ser . "\n";
			fputs($file, $st);
		}

		fclose($file);
	}

	// Process the OUTPUT options
	if ($viewtype == "HTML")
	{
	  // HTML PAGE CREATED HERE
	  ?>


		
<table cellpadding=2 cellspacing=2 border=0 width="330">
  <tr align=center> 
    <th bgcolor="#663300" width="80"><font color="#ffff00" face="Arial, Helvetica, sans-serif" size="1">Rank</font></th>
    <th bgcolor="#663300" width="126"><font color="#FFFF00" face="Arial, Helvetica, sans-serif" size="1">Name</font></th>
    <th bgcolor="#663300" width="104"><font color="#FFFF00" face="Arial, Helvetica, sans-serif" size="1">Score</font></th>
  </tr>
  <?
	
		for ($i = 0; $i < $scoresize; $i++)
		{
			echo ("<tr bgcolor='#669933' align='center'><td><font size='1' face='Arial, Helvetica, sans-serif'>");
			echo ($i + 1);
			echo ("</font></td><td><font size='1' face='Arial, Helvetica, sans-serif'>");
			echo ($tscores[$i][1]);
			echo ("</font></td><td><font size='1' face='Arial, Helvetica, sans-serif'>");
			echo ($tscores[$i][0]);
			echo ("</font></td></tr>");
		}

  	  ?>
</table>
	  <?

	}

	// FLASH DATA CREATED HERE
	if ($viewtype == "FLASH")
	{
		for ($i = 0; $i < $scoresize; $i++)
		{
			echo ("NAME" . $i . "=");
			echo ($tscores[$i][1]);
			echo ("&SCORE" . $i . "=");
			echo ($tscores[$i][0]);
			echo ("&");
		}
	}

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this is scores.php?
DaGoodGames
Forum Newbie
Posts: 6
Joined: Fri Mar 17, 2006 8:59 am

Post by DaGoodGames »

I'm fairly new to PHP, but it looks to me like it would be a bad idea to end the php code in the middle of an if statement and then close the if statement in a seperate php tag. Maybe that's what's causing the curly bracket trouble. Below is the code I'm referring to:

Code: Select all

// Process the OUTPUT options
    if ($viewtype == "HTML")
    {
      // HTML PAGE CREATED HERE
      ?>


        
<table cellpadding=2 cellspacing=2 border=0 width="330">
  <!-- some unrelevant code deleted here ... -->

      <?

    }
Maybe instead of closing the php and starting it up again, you could leave it open and just put the html inside a print or echo command. BUt then again, maybe someone who knows what there talking about will show I'm wrong.

Daniel
Post Reply