在同一页中显示一行的所有结果


Show all results of a row in the same page

我正在尝试显示与其类别相关的所有游戏,我在这里尝试的Sql只显示与游戏5相关的游戏,如何自动显示所有游戏?

<?php
$varCategoria_GameData = "0";
if (isset($_GET["cat"])) {
 $varCategoria_GameData = $_GET["cat"];
}
$sql_categoria = "SELECT * FROM jogos WHERE intCategoria =
( SELECT intCategoria FROM jogos WHERE idGames = 5)";
$query_categoria = mysql_query($sql_categoria, $gameconnection) or die(mysql_error()); 
$categoria = mysql_fetch_assoc($query_categoria);

 ?>

<?php  do { ?> 
<?php echo '<h1>'.$categoria['idGames'].'</h1>'; ?>
 <?php } while ($categoria = mysql_fetch_assoc($query_categoria)); ?>

您要从中删除"WHERE idGames=5"

$sql_categoria = "SELECT * FROM jogos";

查询以"WHERE idGames=5"结束,这实际上意味着它所说的内容。

然后,您可以通过以下方式从$categoria中提取字段:

$categoria['name_of_field'];

意大利语:

Devi togliere"WHERE idGames=5"e farla risultare così:

$sql_categoria = "SELECT * FROM jogos";

Quello chiede alla queryè

"从游戏中选择intCategoria,其中idGames=5";SELEZIONA intCategoria DA jogos DOVE idGamesè5

Poi da$categoria puoi estarre i campi in questo modo:

$categoria['nome_del_campo'];
<?php     
    $sql_categoria = "SELECT * FROM jogos";
    $result_categoria = mysql_query($sql_categoria, $gameconnection) or die(mysql_error()); 
    while($row = mysql_fetch_assoc($result_categoria))
    {
        //Use $row with the index of the field you want to display, or directly with the column name between quote.
        echo "Result :".$row[0]."<br />";
    }
?>

此外,请使用MySQLi函数:http://php.net/manual/fr/book.mysqli.php

避免SQL注入更安全