Jump to content

coollog

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

coollog's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I was making this simple high score list, and I came across a problem, here's my code: <img src="loadingbar.png"/><br/> <center><h2>High Scores List</h2></center> <? $dir=dir("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server"); $arr=array(); while (($file = $dir->read()) !== false){ $path_info = pathinfo("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\".$file); if($path_info['extension']=='acc'){ $ini=parse_ini_file('C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\'.$file); if(isset($_ini['score']) and (real)($ini['score'])>1000){ $arr[basename($file,'.acc')]=$ini['score']; } } } asort($arr,SORT_NUMERIC); $n=1; print_r($arr); foreach($arr as $key=>$val){ echo '#'.$n.' '.$key.' ('.$val.')<br/>'; $n++; } ?> This won't have any values go through the check of if(isset($_ini['score']) and (real)($ini['score'])>1000) But when I change the code to this, there are errors of unknown indexes of score, but it still displays the right ones: <img src="loadingbar.png"/><br/> <center><h2>High Scores List</h2></center> <? $dir=dir("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server"); $arr=array(); while (($file = $dir->read()) !== false){ $path_info = pathinfo("C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\".$file); if($path_info['extension']=='acc'){ $ini=parse_ini_file('C:\Users\coollog\Desktop\Meh Productions\american revolution\Server\\'.$file); if((real)($ini['score'])>1000){ $arr[basename($file,'.acc')]=$ini['score']; } } } asort($arr,SORT_NUMERIC); $n=1; print_r($arr); foreach($arr as $key=>$val){ echo '#'.$n.' '.$key.' ('.$val.')<br/>'; $n++; } ?> Do you know what's wrong? And if you could optimize my code, that would be awesome!
  2. Ok, I have another code that seems to not work, and somehow I can't find the edit topic post button, so ill post here: if (!file_exists($REQUEST["data"])) exit("Highscores table, ".$REQUEST["data"]." doesn't exist!") Please help me fix this, it says some error in the if part.
  3. The bug should be just calculations, not some hard bug, just you need good math.
  4. Yea... Your problem is that you forgot a quotation ending... $daysofweek = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","SaturdayHERE); And a parenthesis ending on if ((isset($_GET[month]) && isset($_GET[day]) && isset($_GET[year])) && (checkdate($_GET[month],$_GET[day],$_GET[year]))HERE So, edited code should be <html> <head> <title>Day of Week Finder</title> <?php $day = date("d"); $month = date("m"); $year = date("Y"); $today = $day; $thismonth = $month; $thisyear = $year; $done = 0; $daysofweek = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); $months = array("month number zero","January","February","March","April","May","June","July","August","September","October","November","December"); if ((isset($_GET[month]) && isset($_GET[day]) && isset($_GET[year])) && (checkdate($_GET[month],$_GET[day],$_GET[year]))) { $month = $_GET[month]; $day = $_GET[day]; $year = $_GET[year]; $done = 1; } if ($done = 0) { $month = $realmonth; $day = $realday; $year = $realyear; $month += 10; $month %= 12; if ($month == 0) $month = 12; if (($month == 12) || ($month == 11)) $year -= 1; $year = $chyeary; $year = $chyearc; $chyeary %= 100; $chyearc = ($chyearc - $chyeary)/100; $total = $day + floor((13 * $month - 1) / 5) + $chyeary + floor($chyeary / 4) + floor($chyearc / 4) - (2 * $chyearc); $total %= 7; $dow = $daysofweek[$total]; $tense = "was"; if (($day == $today) && ($month == $thismonth) && ($year == $thisyear)) $tense = "is"; elseif (($year > $thisyear) || (($year == $thisyear) && ($month > $thismonth)) || (($year == $thisyear) && ($month == $thismonth) && ($day > $today))) $tense = "will be"; } if ($realyear < 1760) $done = 2; ?> </head> <body> <form action="dow.php" method="get"> <table border> <tr bgcolor=black> <th> <input type="text" size=1 maxlength=2 name="month" value=<?php echo $month;?>></th><th> <input type="text" size=1 maxlength=2 name="day" value=<?php echo $day;?>></th><th> <input type="text" size=3 maxlength=4 name="year" value=<?php echo $year;?>></th></tr> <tr bgcolor=blue><td> <small>Month</small></td><td> <small>Day</small></td><td> <small>Year</small></td></tr><tr bgcolor=red><th colspan=3> <input type="submit" value="Calculate"></th></tr></table> </form><br/> <?php if ($done = 1) echo "<h2>" . $day . " " . $months[$month] . " " . $year . " " . $tense . " a " . $dow . ".</h2>"; elseif ($done = 2) echo "<h3>Date must be after 1760.</h3>"; else echo "<h3>Enter any date after 1760.</h3>"; ?> </body> </html>
  5. I can't quite remember, o yea, I added that fgets($file); after the $place=0 (the echo after it was for testing) since the first line has the password after I created the create.php.
  6. Like a couple hours ago, somehow, it was working, but that was b4 I created the other 2 scripts, then I edited it a little, and it went kaploosh... Plus, PHP isn't that hard, and I didn't master it, my creations don't work... EDIT: @Maq The bug is in the scripts, I've been using another server for executing my php files, so please, just help me fix the scripts.
  7. Yea, but I can't fix the server since I don't have access to it. It is down for maintenance. So, uhh, can you solve the bug? I've been trying to fix it for hours already...
  8. My MySQL server site is down so I couldn't make a highscores database in MySQL, which would be a lot easier. I am not that good at PHP since I just started learning the day before yesterday so just please help me. I've been trying to create a PHP highscores database w/o the use of MySQL. It currently has 3 scripts to it, a create.php with parameters data and pass, a add.php with parameters data, pass, name, and score, and a display.php with parameter data. I have some trouble displaying the scores in a list from .dat files you create. It used to work. I also have some trouble adding new names tagged with their scores. Please help! Below are the 3 scripts: display.php <html> <body> <?php if (!isset($_REQUEST["data"])) exit("Invalid highscores data name!"); if (file_exists($_REQUEST["data"].".dat")) $file = fopen($_REQUEST["data"].".dat","r") or exit("Unable to load highscores!"); else exit("Highscores data doesn't exist!"); if (file_exists($_REQUEST["data"].".dat2")) $file2 = fopen($_REQUEST["data"].".dat2","r") or exit("Unable to load highscores!"); else exit("Highscores data doesn't exist!"); $place=0; $pss=fgets($file); echo $pss; while((!feof($file)) && (!feof($file2))) { $place++; $name=fgets($file); echo $name; $score=fgets($file2); echo $score; if(($score!="") and ($name!="")) echo $place."-".$name." ".$score."<br>"; } fclose($file); fclose($file2); ?> </body> </html> create.php (This works fine) <html> <body> <?php if (!isset($_REQUEST["data"])) exit("Invalid highscores data name!"); if (!isset($_REQUEST["pass"])) exit("Invalid highscores data password!"); if (!file_exists($_REQUEST["data"].".dat")) $file=fopen($_REQUEST["data"].".dat","x") or exit("Unable to create highscores data!"); else exit("Highscores data already exists!"); if (!file_exists($_REQUEST["data"].".dat2")) $file2=fopen($_REQUEST["data"].".dat2","x") or exit("Unable to create highscores data!"); else exit("Highscores data already exists!"); fwrite($file,$_REQUEST["pass"]); fclose($file); fclose($file2); echo "Highscores data with name, ".$_REQUEST["data"].", and password, ".$_REQUEST["pass"].", created successfully!" ?> </body> </html> add.php <html> <body> <?php if (!isset($_REQUEST["data"])) exit("Invalid highscores data name!"); if (!isset($_REQUEST["pass"])) exit("Invalid highscores data password!"); if (!isset($_REQUEST["name"])) exit("Invalid entry name!"); if (!isset($_REQUEST["score"])) exit("Invalid entry score!"); if (file_exists($_REQUEST["data"].".dat")) $file = fopen($_REQUEST["data"].".dat","r") or exit("Unable to load highscores!"); else exit("Highscores data doesn't exist!"); if (file_exists($_REQUEST["data"].".dat2")) $file2 = fopen($_REQUEST["data"].".dat2","r") or exit("Unable to load highscores!"); else exit("Highscores data doesn't exist!"); if($_REQUEST["pass"]!=fgets($file)) { fclose($file); fclose($file2); exit("Incorrect password for highscores data, ".$_REQUEST["data"]."!"); } $place=0; while((!feof($file)) && (!feof($file2))) { $place++; $scr=fgets($file2); if($scr<$_REQUEST["score"]) break; } fclose($file); fclose($file2); $file = fopen($_REQUEST["data"].".dat","r+"); $file2 = fopen($_REQUEST["data"].".dat2","r+"); $read = file($_REQUEST["data"].".dat"); $read["Set"]=$_REQUEST["name"]; fwrite($file,$read[0]." "); for($s=1;$s<place;$s++) { fwrite($file,$read[$s+1]); } fwrite($file,$read["Set"]." "); for($s=place+1;$s<=count($read)-1;$s++) { fwrite($file,$read[$s+1]); } fclose($file); $read = file($_REQUEST["data"].".dat2"); $read["Set"]=$_REQUEST["score"]; for($s=0;$s<place-1;$s++) { fwrite($file2,$read[$s]); } fwrite($file2,$read["Set"]." "); for($s=place;$s<=count($read)-2;$s++) { fwrite($file2,$read[$s]); } fclose($file2); include("display.php") ?> </body> </html> If you have any better way to make this, PLEASE tell me, thank you!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.