2013-07-08 68 views
1

我試圖展示所有與它類別相關的遊戲,我在這裏嘗試的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)); ?> 
+0

'SELECT * FROM jogos'測試此查詢 – 2013-07-08 20:21:27

回答

0

您是從

$sql_categoria = "SELECT * FROM jogos"; 

查詢中刪除 「WHERE idGames = 5」 結尾 「WHERE idGames = 5」,這實際上意味着它說什麼。意大利

$categoria['name_of_field']; 

然後你可以提取$ categoria領域這樣

德維togliere 「WHERE idGames = 5」 E farla risultare COSI:

$sql_categoria = "SELECT * FROM jogos"; 

Quello chiede alla查詢è

「SELECT intCategoria FROM jogos WHERE idGames = 5」; SELEZIONA intCategoria DA博彩股份有限公司DOVE idGames E(5)

POI達$ categoria puoi estrarre我坎比在questo MODO:

$categoria['nome_del_campo']; 
+0

嗨,Mr.Web,感謝您的回答,但是我該如何解決玩所有與類別相關的遊戲,我不明白如何把「SELECT * FROM jogos」;將顯示與當前遊戲類別相關的遊戲 –

+0

確定@MariangelaVidotto你可以向我顯示錶格字段嗎?什麼是桌子? –

+0

CREATE TABLE IF NOT EXISTS'jogos'( 'idGames' int(11)NOT NULL AUTO_INCREMENT, 'strNome' varchar(100)DEFAULT NULL, intCategoria' int(11)DEFAULT NULL, –

0
<?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注入

相關問題