Jump to content

Lt Llama

Newly Registered
  • Posts

    11
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Lt Llama's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [quote author=The Little Guy link=topic=123015.msg508001#msg508001 date=1169146077] I'm thinking your looking to do this: http://us3.php.net/manual/en/function.arsort.php [/quote] arsort seems to be good if you want to sort the elements in the array like $myArray = array("b","a") after arsort becomes $myArray = array("a","b"). But thats not my problem. I want to sort like this:. This array content: $myArray[0] = array("1","a") $myArray[1] = array("1","a") $myArray[2] = array("2","c") after sort will be $myArray[2] = array("2","c") $myArray[0] = array("1","a") $myArray[1] = array("1","b") In other words: $myArray[index] = array($sortedValue,$notSortedValue) $myArray[index] = array($sortedValue,$notSortedValue) $myArray[index] = array($sortedValue,$notSortedValue)
  2. I save some values in an array with: [code=php:0]$myArray[$i++] = array($value1,$value2);[/code] Lets say I have the following content of $myArray: $myArray[0]: $value1 = "1", $value2= "a" $myArray[1]: $value1 = "2", $value2= "b" $myArray[2]: $value1 = "3", $value2= "c" $myArray[3]: $value1 = "1", $value2= "d" How do I sort reverse on $value1 so I can use: [code=php:0]for ($j=0; $j <= $i; $j++) {    echo $myArray[$j][0],"...",$myArray[$j][1],"<br>"; }[/code] to print [tt]3 ... c 2 ... b 1 ... a 1 ... d [/tt] I wish I could use something like sort($myArray[$value1]); Sorry, but I just don't get this. Isn't there a simple php function to sort an indexed array based on a value in the array? p.s. $value1 and $value2 contains non unique numbers.
  3. I have a problem which has to be a php version or some php setting problem. The links to player stats on this page http://www.euroskillz.eu/skillsrank/index.php works. The same page here doesnt work: http://www.grumpys.xmgfree.com/phppages/index.php. If you click a link on a player name it should send the cvars to playerstats.php. Thats working in the first page but not the second page. A link looks like this for example: [url=http://85.25.141.71:81/skillsrank/playerstats.php?steamid=STEAM_0:0:1236155&nickname=Lt+Llama&nfinished=120&totalrank=7605&primaryrank=63]http://85.25.141.71:81/skillsrank/playerstats.php?steamid=STEAM_0:0:1236155&nickname=Lt+Llama&nfinished=120&totalrank=7605&primaryrank=63[/url] It is identical on the other page but returns an empty page: http://www.grumpys.xmgfree.com/phppages/playerstats.php?steamid=STEAM_0:1:2211802&nickname=COMBO+RICO&nfinished=1&totalrank=10&primaryrank=10 Playerstats.php which receives this url follows below: [code=php:0]<? include("dbinfo.inc.php"); mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT `steamId`, `mapName`, `curDate`, `difficulty`, `runTime` FROM `skillmaps` WHERE `steamId` = \"$steamid\" ORDER BY mapName ASC"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><br><center><u><font face=verdana size=3 color=F4A21B>Player Stats</b></u></font><br><br> <b><font face=verdana size=4>$nickname</center><b></font><br><br>"; ?> <title>Skillsrank</title> <head> <STYLE type="text/css"> BODY {scrollbar-3dlight-color:#2E8B57; scrollbar-arrow-color:#F4A21B; scrollbar-base-color:#4D5546; scrollbar-track-color:#33382E; scrollbar-darkshadow-color:#000000; scrollbar-face-color:#4D5546; scrollbar-highlight-color:#000000; scrollbar-shadow-color:#404040;} </STYLE> </head> <BODY BGCOLOR="#4D5546" TEXT="#FFFFFF" LINK="#ff9900" VLINK="#ff9900" ALINK="#ff9900" leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0 marginheight=0 marginwidth=0> <div align="center"> <table border="1" bordercolor="#000000" cellspacing="0" cellpadding="0" width="570" style="border-collapse: collapse"> <tr> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"> Finished maps </font></th> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2" color="#00FF00"> Collected points    </font></th> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2" color="#00FFFF">  Average Difficulty </font></th> </tr> <tr> <td align="center" bgcolor="#4c4d43"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$nfinished"; ?></font></td> <td align="center" bgcolor="#4C5844"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$totalrank"; ?></font></td> <td align="center" bgcolor="#4c4d43"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$primaryrank"; ?></font></td> </tr> </table><br><br> <b><br><center><font face=verdana size=3 color=F4A21B>Finished Maps</b></font><br><br> Ordered by Mapname</center><br> <center><font face=verdana size=2> <? $stats1url="<a href=playerstats.php?steamid=" . $steamid . "&nickname=" . urlencode($nickname) . "&nfinished=" . $nfinished . "&totalrank=" . $totalrank . "&primaryrank=" . $primaryrank . " style=\"text-decoration:none\"> Mapname </a>"; $stats2url="<a href=pstatsdate.php?steamid=" . $steamid . "&nickname=" . urlencode($nickname) . "&nfinished=" . $nfinished . "&totalrank=" . $totalrank . "&primaryrank=" . $primaryrank . " style=\"text-decoration:none\"> Date </a>"; $stats3url="<a href=pstatsdiff.php?steamid=" . $steamid . "&nickname=" . urlencode($nickname) . "&nfinished=" . $nfinished . "&totalrank=" . $totalrank . "&primaryrank=" . $primaryrank . " style=\"text-decoration:none\"> Difficulty </a>"; $stats4url="<a href=pstatsruntime.php?steamid=" . $steamid . "&nickname=" . urlencode($nickname) . "&nfinished=" . $nfinished . "&totalrank=" . $totalrank . "&primaryrank=" . $primaryrank . " style=\"text-decoration:none\"> Runtime </a>"; ?> Sort by <? echo $stats1url; ?> | <? echo $stats2url; ?> | <? echo $stats3url; ?> | <? echo $stats4url; ?> </font><br><br></center><br> <div align="center"> <table border="1" bordercolor="#000000" cellspacing="0" cellpadding="0" width="570" style="border-collapse: collapse"> <tr> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"> Mapname </font></th> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2" color="#00FF00"> Date </font></th> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2" color="#00FFFF"> Difficulty </font></th> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2" color="##FF0000"> Runtime </font></th> </tr> <? $i=0; while ($i < $num) { $mapname=mysql_result($result,$i,"mapName"); $curdate=mysql_result($result,$i,"curDate"); $difficulty=mysql_result($result,$i,"difficulty"); $runtime=mysql_result($result,$i,"runTime"); if ($runtime == 0) { $formatTime = "00:00:00"; } else { $hours = ($runtime / 3600) % 24; if ($hours < 10) $hours = "0" . $hours; $minutes = ($runtime / 60) % 60; if ($minutes < 10) $minutes = "0" . $minutes; $seconds = $runtime % 60; if ($seconds < 10) $seconds = "0" . $seconds; $formatTime = $hours . ":" . $minutes . ":" . $seconds; } ?> <tr> <td align="left" bgcolor="#4C5844"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$mapname"; ?></font></td> <td align="center" bgcolor="#4c4d43"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$curdate"; ?></font></td> <td align="center" bgcolor="#4C5844"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$difficulty"; ?></font></td> <td align="center" bgcolor="#4c4d43"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$formatTime"; ?></font></td> </tr> <? ++$i; } echo "</table>"; ?>[/code] Do anyone have any idea why it works in the first page but not the second? /Lt.
  4. I was tired yesterday. I have autoincremented id's. Sorry to confuse you more than necessary. Used them and it seems to work now. [code]<? $i=0; while ($i < $num1) {     $mapname1=mysql_result($result1,$i,"mapName");     $curdbid=mysql_result($result1,$i,"id");     if ($i < ($num1-1)) {         $nextmap1=mysql_result($result1,$i+1,"mapName");         $nextdate1=mysql_result($result1,$i+1,"curDate");         $nextdbid=mysql_result($result1,$i+1,"id");     }     if ($mapname1 != $nextmap1) {         if ($recorddate <= $nextdate1 || $recorddate == "") {             if ($highestid < $curdbid) {                 $highestid=mysql_result($result1,$i+1,"id");                 $recorddate = mysql_result($result1,$i+1,"curDate");                 $nickname=mysql_result($result1,$i+1,"nickNames");                 $recordtime=mysql_result($result1,$i+1,"runTime");                 $time=mysql_result($result1,$i+1,"curTime");                 $recordmap=mysql_result($result1,$i+1,"mapName");             }         }     }     ++$i; }[/code]
  5. [!--quoteo(post=370004:date=Apr 30 2006, 03:35 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 30 2006, 03:35 AM) [snapback]370004[/snapback][/div][div class=\'quotemain\'][!--quotec--] Then I don't understand your question. You want the top speed run for each map, and then how do the date/time columns fit in? [/quote] I want only one record in the output, the latest speedrun. I have a script which outputs the speed run record for every map. Now from those I want to pick the latest. I find the most rescent date when a record was broken, but the problem is when there are multiple records in the same day. Sorry if I cant explain any better. If I could I could probably solve it :).
  6. [!--quoteo(post=369962:date=Apr 29 2006, 10:50 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 29 2006, 10:50 PM) [snapback]369962[/snapback][/div][div class=\'quotemain\'][!--quotec--] Why are you storing curDate and curTime separately? And why are these not present in the order by clause? [/quote] Just a descision i did at the start. The time and date comes from the server time and date, picked by a plugin made for a game. I never thought about that I could have them in the same field. The reason i dont have them in the order by clause is that I want the result handle to contain groups of map names, and within each map name group i want the best time at the top.
  7. [!--quoteo(post=369943:date=Apr 29 2006, 09:27 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Apr 29 2006, 09:27 PM) [snapback]369943[/snapback][/div][div class=\'quotemain\'][!--quotec--] If you have auto-incremented records, then the most recent record can be found with [a href=\"http://ca.php.net/manual/en/function.mysql-insert-id.php\" target=\"_blank\"]the mysql-insert-id function[/a] [/quote] Sorry, i was maybe unclear. With record i mean a speed run record. Not a databse record. maybe you didnt mean that anyway :). The best I can do is to sort on map names and then sort ascending on the finish time within the list of maps. And i was an idiot when i made the db. No auto increment used. Can I add this somehow afterwards? This is what is in the result handle, i give an example. [b]steam id ; nickNames ; mapName ; curDate ; runTime ; curTime[/b] ----------------------------------------------------- row 1: id ; nick ; map_a ; 2006/02/06 ; 200 ; 13:19:05 row 2: id ; nick ; map_a ; 2006/02/06 ; 300 ; 13:40:05 row 3: id ; nick ; map_a ; 2006/02/06 ; 400 ; 13:45:05 row 4: id ; nick ; map_b ; 2006/02/07 ; 300 ; 18:19:05 row 5: id ; nick ; map_b ; 2006/02/07 ; 400 ; 18:40:05 row 6: id ; nick ; map_b ; 2006/02/07 ; 500 ; 19:45:05 row 7: id ; nick ; map_c ; 2006/02/07 ; 300 ; 08:19:05 row 8: id ; nick ; map_c ; 2006/02/07 ; 400 ; 08:40:05 row 9: id ; nick ; map_c ; 2006/02/07 ; 500 ; 09:45:05 The result handle is as you can see sorted on mapName and then column runTime. The script should return row 4 as this is the most rescent record. Instead it returns row 7.
  8. Hi Getting numb trying to figure this one out. I have a db with a list of game map names. Each map can be speedrun. When someone finish the time is saved. People can choose not to speedrun, the runtime is then 0. [code]$query="SELECT `steamId`,`nickNames`, `mapName`, `curDate`, `runTime`,`curTime` FROM `skillmaps` WHERE runTime > 0 ORDER BY `mapName` ASC, `runTime` ASC";[/code] The query above pics all speedruns which are > 0. It sorts it on 1. Map name 2. The finish time Now, from this i want to find out which is the last speed run record done. Ill come so far that it shows the last map which had a speed run per date. BUT, if there was several speedruns the same day it doesnt work. Why? Because the script dont check if the speedrun was done the same day and do a time sort. I tried but I just mess it up. The while loop below should return the latest speedrun. [code]<? $i=0; while ($i < $num1) {     $mapname1=mysql_result($result1,$i,"mapName");     $curtime=mysql_result($result1,$i,"curTime");     if ($i < ($num1-1)) {         $nextmap1=mysql_result($result1,$i+1,"mapName");         $nextdate1=mysql_result($result1,$i+1,"curDate");     }     if ($mapname1 != $nextmap1) {         if ($recorddate <= $nextdate1 || $recorddate == "") {             $recorddate = mysql_result($result1,$i+1,"curDate");             $nickname=mysql_result($result1,$i+1,"nickNames");             $recordtime=mysql_result($result1,$i+1,"runTime");             $time=mysql_result($result1,$i+1,"curTime");             $recordmap=mysql_result($result1,$i+1,"mapName");         }     }     ++$i; }[/code] My question is, can I change my sql query so I dont have to mess with the conditions? I.e. would it be possible to get 1 line in the result handle, only showing the latest record? That would be awsome. If not, any suggestion would be appreciated. The output where i want this is the upper part of this page: [a href=\"http://skill.tfc4ever.de/skillsrank/runrecords.php\" target=\"_blank\"]http://skill.tfc4ever.de/skillsrank/runrecords.php[/a] Thx /Lt.
  9. [!--quoteo(post=351436:date=Mar 3 2006, 10:36 PM:name=villav)--][div class=\'quotetop\']QUOTE(villav @ Mar 3 2006, 10:36 PM) [snapback]351436[/snapback][/div][div class=\'quotemain\'][!--quotec--] you can do it in query: SELECT `nickNames`, `mapName`, `curDate`, `runTime` FROM `skillmaps` ORDER BY `mapName` ASC", `runTime` ASC so it'll sort by mapName and then by runtime. Just out the result. [/quote] You just gotta love SQL queries, it never occured to me that I could sort the run times after sorting the map names. Thanks for opening my eyes. And the script will probably be faster to. [!--quoteo(post=351451:date=Mar 4 2006, 12:01 AM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 4 2006, 12:01 AM) [snapback]351451[/snapback][/div][div class=\'quotemain\'][!--quotec--] See if this works for you: [/quote] Thx wickning1. I could probably learn a lot from looking at your query :). But its something wrong in the result set. I tried and it gives me: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /srv/www/htdocs/web3/html/skillsrank/slask1.php on line 39 /Lt
  10. Im just taking a chance here. Do you need all the columns when you select from table? If you dont need it you could specify the columns you want in your query. If you have to many queries maybe you could cut down on them and check the content in a while loop. Just store more data in the result handle. Also, where do you have your mysql_close();? You could try to close and open db after each query maybe. But an index is probably the best. Im a noob but if im lucky this could help you. If not, sorry for pointing out something obvius. /Lt
  11. Hi! My first post on these forums, and a post of desperation. I have been working on a rank and speedrun system for one of the Half-Life mods for 2 months. Last part to get working is a php page to show the best speedruns done on the maps. All info are stored in an SQL database. I have deleted and remade the while loop several times but its just not working. The output of the script is [a href=\"http://skill.tfc4ever.de/skillsrank/runrecords.php\" target=\"_blank\"]http://skill.tfc4ever.de/skillsrank/runrecords.php[/a] The problem is that the nickname and record date is wrong. Im doing something stupid in the while loop looking through the SQL handle. Can any smart person see where the error/erros are? The sql array handle which I pick from the db is sorted on mapname and has the 4 columns: Nickname, Mapname, Date finished, Speed run time. The outer while loop runs through the sql handle. The inner while loop compares the speedrun times while the map name is the same. When the inner loop is done it saves the best time and prints it. The speed run times are stored in seconds. Any help would be appreciated, as this is the last part of the system before its done. Thx /Lt [code] <? include("dbinfo.inc.php"); mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT `nickNames`, `mapName`, `curDate`, `runTime` FROM `skillmaps` ORDER BY `mapName` ASC"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><br><center><u><font face=verdana size=3 color=F4A21B>Skill@TFC4ever.de - Speed Run Records</b></u></font><br><br><br>"; ?> <title>Skill@TFC4ever.de - Speed run records</title> <head> <STYLE type="text/css"> BODY {scrollbar-3dlight-color:#2E8B57;     scrollbar-arrow-color:#F4A21B;     scrollbar-base-color:#4D5546;     scrollbar-track-color:#33382E;     scrollbar-darkshadow-color:#000000;     scrollbar-face-color:#4D5546;     scrollbar-highlight-color:#000000; scrollbar-shadow-color:#404040;} </STYLE> </head> <BODY BGCOLOR="#4D5546" TEXT="#FFFFFF" LINK="#ff9900" VLINK="#ff9900" ALINK="#ff9900" leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0 marginheight=0 marginwidth=0> <div align="center"> <table border="1" bordercolor="#000000" cellspacing="0" cellpadding="0" width="570" style="border-collapse: collapse"> <tr> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2">  Mapname </font></th> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2" color="#00FF00">  Nickname  </font></th> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2" color="#00FFFF">  Record Date </font></th> <th align="center" bgcolor="#403F2E"><font face="verdana, Arial, Helvetica, sans-serif" size="2" color="#FF0000">  Runtime  </font></th> </tr> <? $i=0; while ($i < $num) {     $mapname=mysql_result($result,$i,"mapName");     $nextmap=mysql_result($result,$i,"mapName");     $recordtime = 0;     $recordset = 0;          while (($mapname == $nextmap) && ($i < $num)) {         $runtime=mysql_result($result,$i,"runTime");         if ($recordset == 0) {             if ($runtime > 0) {                 $recordtime = $runtime;                 $recordset = 1;                 $nickname=mysql_result($result,$i-1,"nickNames");                 $curdate=mysql_result($result,$i-1,"curDate");             }         }         if ($i < $num-1) {             $nexttime=mysql_result($result,$i+1,"runTime");             $nextmap=mysql_result($result,$i+1,"mapName");             if ($mapname == $nextmap) {                 if ($nexttime < $recordtime && $nexttime > 0) {                     $recordtime = $nexttime;                     $nickname=mysql_result($result,$i+1,"nickNames");                     $curdate=mysql_result($result,$i+1,"curDate");                 } else {                     $nickname=mysql_result($result,$i,"nickNames");                     $curdate=mysql_result($result,$i,"curDate");                 }             } else {                 if ($recordtime > 0) {                     $hours = ($recordtime / 3600) % 24;                     if ($hours < 10)                         $hours = "0" . $hours;                     $minutes = ($recordtime / 60) % 60;                     if ($minutes < 10)                         $minutes = "0" . $minutes;                     $seconds = $recordtime % 60;                     if ($seconds < 10)                         $seconds = "0" . $seconds;                     $formatTime = $hours . ":" . $minutes . ":" . $seconds;                                          ?>                     <tr>                     <td align="left" bgcolor="#4C5844"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$mapname"; ?></font></td>                     <td align="center" bgcolor="#4c4d43"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$nickname"; ?></font></td>                     <td align="center" bgcolor="#4C5844"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$curdate"; ?></font></td>                     <td align="center" bgcolor="#4c4d43"><font face="verdana, Arial, Helvetica, sans-serif" size="2"><? echo "$recordtime"; ?></font></td>                     </tr>                     <?                 }             }         }         ++$i;     } } echo "</table>"; ?> [/code]
×
×
  • 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.