2017-01-30 9 views
0

私は基本的に私のゲームサーバー用のこのクイックスタットシャワーをコーディングしていましたが、私はそれをID番号にします。PHP、行IDの作業をしようとしています

<html> 
<head> 
    <meta charset="utf-8"> 
    <title>ExileMod Stats</title> 

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> 
</head> 

<body> 
    <div class="container"> 
<?php 
$con=mysqli_connect("******","******","******","******"); //server address, username, password, dbname 
// Check connection 
if (mysqli_connect_errno()) 
{ 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 
    //check order ascending or descending 
    if (isset($_GET["order"])) { 
     $sort = $_GET["order"]; 
     if ($_GET["order"] == "asc"){ 
      $sort = "desc"; 
      $order = "asc"; 
     } 
     else{ 
      $sort = "asc"; 
      $order = "desc"; 
     } 
    } 

    //check filter 
    if (isset($_GET["name"])) { 
     $name = $_GET["name"]; 
     } 
      else { 
      $name = "name"; 
       } 
$list=array('name', 'money', 'score', 'kills', 'deaths', 'uniform', 'vest', 'last_updated_at'); 
if (in_array($name,$list)) 
{ 
    //variable ok 
} 
    else 
    { 
     $name = "name"; 
    } 

$query = mysqli_query($con,"SELECT * FROM account a INNER JOIN player p ON a.uid = p.account_uid ORDER BY a.$name $order"); 
?><!--//echo "<table border='1'>--> 
<style> 
table { 
    font-family: arial, sans-serif; 
    border-collapse: collapse; 
    width: 100%; 
} 

td, th { 
    border: 1px solid #dddddd; 
    text-align: left; 
    padding: 8px; 
} 

tr:nth-child(even) { 
    background-color: #dddddd; 
} 
</style> 
<table class="table"> 
<tr> 
<?php echo "<th><a href=\"?order=$sort&name=name\">Player Name</a></th>";?> 
<?php echo "<th><a href=\"?order=$sort&name=money\">Money</a></th>";?> 
<?php echo "<th><a href=\"?order=$sort&name=score\">Score</a></th>";?> 
<?php echo "<th><a href=\"?order=$sort&name=kills\">Kills</a></th>";?> 
<?php echo "<th><a href=\"?order=$sort&name=deaths\">Deaths</a></th>";?> 
<?php echo "<th><a href=\"?order=$sort&name=uniform\">Uniform</a></th>";?> 
<?php echo "<th><a href=\"?order=$sort&name=vest\">Vest</a></th>";?> 
<?php echo "<th><a href=\"?order=$sort&name=last_updated_at\">Last Updated</a></th>";?> 
</tr> 
<!--//";--> 
<?php 

while($row = mysqli_fetch_array($query)) 
{ 
?><tr class="danger"><?php 
echo "<td>" . $row['name'] . "</td>"; 
echo "<td>" . $row['money'] . "</td>"; 
echo "<td>" . $row['score'] . "</td>"; 
echo "<td>" . $row['kills'] . "</td>"; 
echo "<td>" . $row['deaths'] . "</td>"; 
echo "<td>" . $row['uniform'] . "</td>"; 
echo "<td>" . $row['vest'] . "</td>"; 
echo "<td>" . $row['last_updated_at'] . "</td>"; 
echo "</tr>"; 
} 
echo "</table>"; 

mysqli_close($con); 
?> 
<a href="http://heroesofgaming.co.uk">© HeroesOfGaming 2016 - 2017</a> 
</div> 
</body> 
</html> 

だから私は数字を入れて、それがデータベースから選択されているが、多くのプレイヤーに1 2 3 4 5 6 7をカウントし、そうしようとしていますか?うまくいけば、これは理にかなっている。

答えて

0

あなたは働いているか、またはまったくの行番号が表示されないようではありません。この

<?php 

$i = 0; // <--- Added this 
while($row = mysqli_fetch_array($query)) 
{ 
$i++; // <--- Added this 
?><tr class="danger"><?php 
echo "<td>". $i . "</td>"; // <--- Added this 
echo "<td>" . $row['name'] . "</td>"; 
echo "<td>" . $row['money'] . "</td>"; 
echo "<td>" . $row['score'] . "</td>"; 
echo "<td>" . $row['kills'] . "</td>"; 
echo "<td>" . $row['deaths'] . "</td>"; 
echo "<td>" . $row['uniform'] . "</td>"; 
echo "<td>" . $row['vest'] . "</td>"; 
echo "<td>" . $row['last_updated_at'] . "</td>"; 
echo "</tr>"; 
} 
echo "</table>"; 

mysqli_close($con); 
?> 
+0

のように行うことができます。 – Asylum

+0

番号を表示する場所はどこですか? –

+0

IDの列を作成して、1から最後の数字が何であれ例: http://prntscr.com/e29reh – Asylum

関連する問題