我有一个名为categoria的表,有10行:
(idcateg, descri) VALUES
(1, 'Action'),
(2, 'Classic'),
(3, 'Fight'),
(4, 'Others'),
(5, 'Puzzles'),
(6, 'Racing'),
(7, 'Shooting'),
(8, 'Sports'),
(9, 'Tower Defense'),
(10, 'Zombie');
并且它都链接到名为link_categoria.php的页面
<a href="link_categoria.php?cat=1">Action</a>
<a href="link_categoria.php?cat=2">Classic</a>
<a href="link_categoria.php?cat=3">Fight</a>
<a href="link_categoria.php?cat=4">Others</a>
...
我想知道的是,像这个网站:http://www.gameonline.org 我想点击类别时更改每个页面的信息。我该怎么做?
由于
mysql_select_db($database_gameconnection, $gameconnection);
$query_Recordset1 = "SELECT * FROM categoria ORDER BY categoria.descri";
$Recordset1 = mysql_query($query_Recordset1, $gameconnection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
while ($row_Recordset1 = mysql_fetch_assoc($Recordset1))
{
echo '<a href="link_categoria.php?cat='.
$row_Recordset1['idcateg'] .'">'.
$row_Recordset1['descri']. '</a><br>';
}
答案 0 :(得分:0)
在link_categoria.php
上,您可以使用$_GET['cat']
// Check if $_GET['cat'] is set [ie. ?cat=##] and is numeric
if(isset($_GET['cat']) && is_numeric($_GET['cat'])){
// Get categoria and escape it before using in the query
$cat = mysql_real_escape_string($_GET['cat']);
// Query to get categoria title
$sql_categoria = "SELECT * FROM categoria WHERE idcateg = $cat";
$query_categoria = mysql_query($sql_categoria, $gameconnection) or die(mysql_error());
$categoria = mysql_fetch_assoc($query_categoria);
// Echo the categoria title
echo '<h1>'.$categoria['descri']. '</h1>';
} // ends if(isset($_GET['cat']) && is_numeric($_GET['cat']))
假设您有按照列表列出的游戏表
gameid | idcateg | game
1 3 game1
2 5 game2
....
您可以执行类似的查询以获取该类别中的游戏列表
// Check if $_GET['cat'] is set [ie. ?cat=##] and is numeric
if(isset($_GET['cat']) && is_numeric($_GET['cat'])){
// Get categoria and escape it before using in the query
$cat = mysql_real_escape_string($_GET['cat']);
$query_Recordset1 = "SELECT * FROM games WHERE idcateg = $cat";
$Recordset1 = mysql_query($query_Recordset1, $gameconnection) or die(mysql_error());
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
while ($row_Recordset1 = mysql_fetch_assoc($Recordset1))
{
echo '<a href="game.php?gameid='.
$row_Recordset1['gameid'] .'">'.
$row_Recordset1['game']. '</a><br>';
}
}
请注意,从文档开始 - 自PHP 5.5.0起,mysql_*
扩展名已弃用,将来将被删除。相反,应使用MySQLi或PDO_MySQL扩展名。有关详细信息,另请参阅MySQL: choosing an API指南和related FAQ。