2016-09-24 2 views
0

私は一列のみデータベースから読み取る必要がある、と行を分離生成する情報の これはコードです:私が最初にAUTHID選択する必要がMySQLのクエリが発生

<?php 
 
session_start(); 
 
ob_start(); 
 
error_reporting(E_ERROR | E_WARNING | E_PARSE); 
 
ini_set("display_errors", 1); 
 
set_time_limit(10); 
 

 
// database connection 
 
$sql_ip = "localhost"; 
 
$sql_user = "mysql_user"; 
 
$sql_password = "mysql_password"; 
 
$sql_database = "database_name"; 
 

 
$dbc = mysql_connect($sql_ip, $sql_user, $sql_password); 
 
if (!$dbc) { 
 
    die('Could not connect: ' . mysql_error()); 
 
} 
 
mysql_select_db($sql_database); 
 

 
if($_GET["order"]){ 
 
    if($_SESSION["orders"][$_GET["order"]]=="ASC" || $_SESSION["orders"][$_GET["order"]]==""){ 
 
     $order=" ".$_GET["order"]." DESC "; 
 
     $_SESSION["orders"][$_GET["order"]]="DESC"; 
 
    } 
 
    elseif($_SESSION["orders"][$_GET["order"]]=="DESC"){ 
 
     $order=" ".$_GET["order"]." ASC "; 
 
     $_SESSION["orders"][$_GET["order"]]="ASC"; 
 
    } 
 
}else{ 
 
    $order="skillpoints DESC"; 
 
} 
 

 
$sql="SELECT * FROM skillpoints_v2 ORDER BY $order LIMIT 30"; 
 
$db=mysql_query($sql); 
 
while($b=mysql_fetch_array($db, MYSQL_ASSOC)) { \t \t 
 
\t $players[]=$b; 
 
} 
 

 
function convert_steamid($string) { 
 
    $steamid  = strtolower($string); 
 
    $tmp   = explode(':',$steamid); 
 
    $steamcid  = (($tmp[2]*2)+$tmp[1]) + 1197960265728; 
 
    $formatted_cid  = number_format($steamcid, 0, '.', ''); 
 
    return 'http://steamcommunity.com/profiles/7656' . $formatted_cid; 
 
} 
 
?> 
 

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head> 
 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
 
<title>SkillPoints</title> 
 
<link href="style.css" rel="stylesheet" type="text/css" /> 
 
</head> 
 
<body> 
 
<table id="mytable" cellspacing="0"> 
 
    <tr> 
 
     <th scope="col" abbr="POSITION">#</th> 
 
     <th scope="col" abbr="NICK">NICK</th> 
 
     <th scope="col" abbr="KILLS"><a href="?order=kills">KILLS</a></th> 
 
\t \t <th scope="col" abbr="DEATHS"><a href="?order=deaths">DEATHS</a></th> 
 
\t \t <th scope="col" abbr="HEADSHOTS"><a href="?order=headshots">HEADSHOTS</a></th> 
 
\t \t <th scope="col" abbr="KNIFE-KILLS"><a href="?order=knife_kills">KNIFE KILLS</a></th> 
 
\t \t <th scope="col" abbr="KNIFE-DEATHS"><a href="?order=knife_deaths">KNIFE DEATHS</a></th> 
 
\t \t <th scope="col" abbr="GRENADE-KILLS"><a href="?order=grenade_kills">GRENADE KILLS</a></th> 
 
\t \t <th scope="col" abbr="GRENADE-DEATHS"><a href="?order=grenade_deaths">GRENADE DEATHS</a></th> 
 
\t \t <th scope="col" abbr="BOMB-EXPLOSIONS"><a href="?order=bomb_explosions">BOMB EXPLOSIONS</a></th> 
 
\t \t <th scope="col" abbr="DEFUSED-BOMBS"><a href="?order=defused_bombs">DEFUSED BOMBS</a></th> 
 
\t \t <th scope="col" abbr="OWN-ROUNDS"><a href="?order=own_rounds">OWN ROUNDS</a></th> 
 
\t \t <th scope="col" abbr="SKILLPOINTS"><a href="?order=skillpoints">SKILLPOINTS</a></th> 
 
    </tr> 
 
    <?php $i=0;foreach($players as $player){$i++;?> 
 
    <tr> 
 
     <th scope="row" class="spec<?php print ($i%2==0?'alt':'')?>"><?php print $i?></th> 
 
\t \t <td><a href="<?php print convert_steamid($player["authid"])?>" target="_blank"><?php print $player["nick"]?></a></td> 
 
     <td><?php print $player["kills"]?></td> 
 
\t \t <td><?php print $player["deaths"]?></td> 
 
\t \t <td><?php print $player["headshots"]?></td> 
 
\t \t <td><?php print $player["knife_kills"]?></td> 
 
\t \t <td><?php print $player["knife_deaths"]?></td> 
 
\t \t <td><?php print $player["grenade_kills"]?></td> 
 
\t \t <td><?php print $player["grenade_deaths"]?></td> 
 
\t \t <td><?php print $player["bomb_explosions"]?></td> 
 
\t \t <td><?php print $player["defused_bombs"]?></td> 
 
\t \t <td><?php print $player["own_rounds"]?></td> 
 
\t \t <td><?php print $player["skillpoints"]?></td> 
 
    </tr> 
 
    <?php }?> 
 
</table> 
 
</body> 
 
</html>

、誰もが死や死などを生み出します。 私は何ができ、どのように動作するのか分かりません。

+1

にこのコードを変更する必要がありますし、 mysqliまたは 'PDO'に貼り付けてください – Drew

+1

**警告**:PHPを学んでいるだけの方は、古い[mysql_query'](http:// php .net/manual/en/function.mysql-query.php)インタフェースを使用します。それはひどいので、PHP 7では削除されました。[PDOは学ぶのが難しくありません](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo- for database-access /)、[PHP The Right Way](http://www.phptherightway.com/)のようなガイドはベストプラクティスの説明に役立ちます。 **あなたのユーザーパラメータが[正しくエスケープされている](http://bobby-tables.com/php)か、重大な[SQLインジェクションバグ](http://bobby-tables.com/ )。 – tadman

答えて

3

SQLクエリに問題があります。 変数$ orderの値を使用していません。

$sql="SELECT * FROM skillpoints_v2 ORDER BY ".$order." LIMIT 30"; 
0

おそらく使用してみてください、あなたはmysql_`デシベル層 `の乗り降り、あなただけ出始めているので

$sql="SELECT * FROM skillpoints_v2 ORDER BY $order LIMIT 30"; 
$db=mysql_query($sql); 
while($b=mysql_fetch_array($db, MYSQL_ASSOC)) {  
    $players[]=$b; 
} 

$sql="SELECT * FROM skillpoints_v2 ORDER BY $order LIMIT 30"; 
$result = $dbc->query($sql); 
if ($result->num_rows > 0) { 
    // output data of each row 
    while($row = $result->fetch_assoc()) { 
     // display your data 
    } 
} else { 
    echo "0 results"; 
} 
関連する問題