gpt4 book ai didi

php - 更改类别页面的内容

转载 作者:行者123 更新时间:2023-11-30 23:19:15 27 4
gpt4 key购买 nike

我有一个名为 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>';
}

最佳答案

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>';
}
}

请注意,从文档中可以看出,mysql_* 扩展已从 PHP 5.5.0 开始弃用,并将在未来删除。相反,MySQLiPDO_MySQL应该使用扩展名。另见 MySQL: choosing an API指南和related FAQ获取更多信息。

关于php - 更改类别页面的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16269809/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com