Page 1 of 1

need help with float values!! [newbie]

Posted: Fri May 20, 2005 12:47 am
by YDEK
somebody please tell me whats wrong here!!! it keeps changing $wintime to 0 for some reason...im sorry, but im new to php and im pretty much just modifying this script i found to suit my needs, the script is for a game im making in flash and its supposed to show the top 10 fastest times...everything else works, except this!!:mad:

Code: Select all

<?php

	$wintime = $_GET['wintime'];
	settype ($wintime,"double"); //also tried "float"
	$winname = $_GET['winname'];
	$viewtype = $_GET['viewtype'];
	$action = $_GET['action'];
	$filename = "scores.sco";
	$scoresize = 10;

	// 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/9999
	for ($i = $numreadin; $i < $scoresize; $i++)
	{
		$tscores[$i][0] = 9999;
		$tscores[$i][1] = "none";
	}

	// Process the actions	

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

		// Add name to end of list, and sort
		$tscores[$scoresize + 1][0] = $wintime;
		$tscores[$scoresize + 1][1] = $winname;
		sort ($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] = 9999;
		$k[1] = "none";
		$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="152">
		<tr align=center> 
		<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">#</font></th>
		<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Name</font></th>
		<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Time</font></th>
		</tr>

   	  <?
	
		for ($i = 0; $i < $scoresize; $i++)
		{
			echo ("<tr bgcolor='#666666' align='center'><td><font size='2' face='Arial, Helvetica, sans-serif'>");
			echo ($i + 1);
			echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
			echo ($tscores[$i][1]);
			echo ("</font></td><td><font size='2' 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 ("&time" . $i . "=");
			echo ($tscores[$i][0]);
			echo ("&");
		}
	}

?>
:x

Posted: Fri May 20, 2005 3:43 am
by phpScott
what is winTime's value before you try to set its type.

Posted: Fri May 20, 2005 6:12 am
by YDEK
it comes through as a time in seconds...for example: 5.678

Posted: Fri May 20, 2005 11:49 am
by YDEK
nevermind, ill just multiply the value by 1000 before sending it to the php so it can be handled as an integer, then it works fine...thanks anyways