Jump to content

Recommended Posts

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]<?php
include '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]
Link to comment
https://forums.phpfreaks.com/topic/33767-insert-to-table-the-no-of-rank/
Share on other sites

OK, i have done it: Needs some corrections but it works :P  Problem solved

[code]<?php
include '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]

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]<?php
include '../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]
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.