prima Posted January 11, 2007 Share Posted January 11, 2007 ok, i have searched for a ranking system but i have found all that display you the resault i just want to put the no. in the table.Something like this:[code]<?phpinclude 'connect.php';//ranking by strike power$sql=" SELECT strikepower FROM account ORDER BY strikepower DESC"; $rank=mysql_query($sql) or die ('Failed'. mysql_error());//now i want to insert to the first result number 1 to the second no. 2 to the third no. 3 etc.<br>//the 1,2,3 should insert into rankstrike//query result : this is how i like it to be at the end/* strike power rankstrike<br> 20000 1<br> 17400 2<br> etc etc */?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33767-insert-to-table-the-no-of-rank/ Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 It doesn't look as thought there's a unique column there, is there?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33767-insert-to-table-the-no-of-rank/#findComment-158343 Share on other sites More sharing options...
prima Posted January 11, 2007 Author Share Posted January 11, 2007 i think of a while function and there i could insert the no. hm... let me check something Quote Link to comment https://forums.phpfreaks.com/topic/33767-insert-to-table-the-no-of-rank/#findComment-158344 Share on other sites More sharing options...
prima Posted January 11, 2007 Author Share Posted January 11, 2007 OK, i have done it: Needs some corrections but it works :P Problem solved[code]<?phpinclude 'povezavadb.php';//ranking by strike power$sql=" SELECT strikepower, ID_name FROM account ORDER BY strikepower DESC"; $rank=mysql_query($sql) or die ('Failed'. mysql_error());echo "Strike power: <br>";$i=1;while ($row = mysql_fetch_array($rank, MYSQL_NUM)) { echo "$i : ".$row[0]; $insert="UPDATE account SET rankstrike='$i' WHERE strikepower='$row[0]'"; $insert2=mysql_query($insert) or die ('Failed'. mysql_error()); echo "\n <br>"; $i=$i+1;}mysql_free_result($rank);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33767-insert-to-table-the-no-of-rank/#findComment-158366 Share on other sites More sharing options...
HuggieBear Posted January 11, 2007 Share Posted January 11, 2007 Yeah, you really needed that unique column ;DHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33767-insert-to-table-the-no-of-rank/#findComment-158371 Share on other sites More sharing options...
prima Posted January 11, 2007 Author Share Posted January 11, 2007 Next problem : i have rank in strike power, def, show, hide i put them all in one .php file, but it edits only the strike rank[code]<?phpinclude '../povezavadb.php';session_start();//ranking by strike power$sql=" SELECT strikepower, ID_name FROM account ORDER BY strikepower DESC"; $rank=mysql_query($sql) or die ('Failed'. mysql_error());echo "Strike power: <br>";$i=1;while ($row = mysql_fetch_array($rank, MYSQL_NUM)) { echo "$i : ".$row[0]; $insert="UPDATE account SET rankstrike='$i' WHERE strikepower='$row[0]'"; $insert2=mysql_query($insert) or die ('Failed'. mysql_error()); echo "\n <br>"; $i=$i+1;}mysql_free_result($rank);//ranking by def power$sqlD=" SELECT defpower, ID_name FROM account ORDER BY defpower DESC"; $rankD=mysql_query($sqlD) or die ('Failed'. mysql_error());echo "Def power: <br>";$iD=1;while ($rowD = mysql_fetch_array($rankD, MYSQL_NUM)) { echo "$iD : ".$rowD[0]; $insertD="UPDATE account SET rankdef='$iD' WHERE rankdef='$rowD[0]'"; $insertDD=mysql_query($insertD) or die ('Failed'. mysql_error()); echo "\n <br>"; $iD=$iD+1;}//mysql_free_result($insertDD);//ranking by hide power$sqlH=" SELECT hidepower, ID_name FROM account ORDER BY hidepower DESC"; $rankH=mysql_query($sqlH) or die ('Failed'. mysql_error());echo "Hide power: <br>";$i=1;while ($row = mysql_fetch_array($rankH, MYSQL_NUM)) { echo "$i : ".$row[0]; $insertH="UPDATE account SET rankhide='$i' WHERE rankhide='$row[0]'"; $insert2H=mysql_query($insertH) or die ('Failed'. mysql_error()); echo "\n <br>"; $i=$i+1;}//mysql_free_result($rankH);//ranking by show power$sqlS=" SELECT showpower, ID_name FROM account ORDER BY showpower DESC"; $rankS=mysql_query($sqlS) or die ('Failed'. mysql_error());echo "Show power: <br>";$i=1;while ($row = mysql_fetch_array($rankS, MYSQL_NUM)) { echo "$i : ".$row[0]; $insertS="UPDATE account SET rankshow='$i' WHERE rankshow='$row[0]'"; $insert2S=mysql_query($insertS) or die ('Failed'. mysql_error()); echo "\n <br>"; $i=$i+1;}//mysql_free_result($rankS);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33767-insert-to-table-the-no-of-rank/#findComment-158388 Share on other sites More sharing options...
prima Posted January 11, 2007 Author Share Posted January 11, 2007 Never mind, a small but important mistake, here is the correction in this lines: [code]$insertH="UPDATE account SET rankhide='$i' WHERE hidepower='$row[0]'";[/code] [code]$insertD="UPDATE account SET rankdef='$iD' WHERE defpower='$rowD[0]'"[/code]; [code]$insert="UPDATE account SET rankstrike='$i' WHERE strikepower='$row[0]'"[/code];[code]$insertS="UPDATE account SET rankshow='$i' WHERE showpower='$row[0]'";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33767-insert-to-table-the-no-of-rank/#findComment-158502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.