gpt4 book ai didi

php - 如何使用 PHP 和 MySQL 将 URL 类别编号更改为单词?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:45:58 26 4
gpt4 key购买 nike

我一年前买了一个 iPhone 壁纸库 PHP 脚本,它运行得很好。我一直在慢慢地学习 PHP 和 MySQL,通过在这里和那里做一些小调整。

要查看类别,URL 是 www.example.com/index.php?catid=27,我想将其更改为 www.example.com/index。 php?catid=apple 出于 SEO 原因。我知道我可以使用 .htaccess 进一步整理 URL,但我只想以这个单词 slug 开头。

我认为这是生成类别页面的代码(在 index.php 中):

if (($_REQUEST['catid']) && ($_REQUEST['catid'] > 1)) {
$catid = $_REQUEST['catid'];
if (is_numeric($catid)) {
$tempitemarray = $myitems->getItemsByCategory($catid);
$catnav = "&catid=" . $catid;
$tempcat = new Category();
$tempcat->getCategory($catid);
$maintitle = "<h1>" . $tempcat->getCategoryName() . " " . $itemplural . "</h1>";
}

该代码调用另一个名为 itemList.php 的 PHP 页面,在该页面中我找到了这段代码:

public function getItemsByCategory($catid) {
$this->retrieveSQL = "select * from items i, item_category_lookup l where livedate < '" . $this->currentdate . "' and i.active = " . $this->showApproved . " and l.categoryid = $catid and i.id = l.itemid order by i.livedate desc limit " . $this->startRow . "," . $this->numRows;
$this->countSQL = "select * from items i, item_category_lookup l where livedate < '" . $this->currentdate . "' and i.active = " . $this->showApproved . " and l.categoryid = $catid and i.id = l.itemid";
$this->retrieveItems();
return $this->items;
}

这是“项目”表:

    id | itemname | itemdec | itemkeywords | createdate | viewcount | active | rating | livedate | sourcedesc | sourceurl
-----------------------------------
64 | Apple Logo

这是“item_category_lookup”表:

categoryid | itemid
-------------------------
27 | 64

这是下面的“类别”表格。它没有在上面的查询中调用,但确实有实际的类别名称。我将如何实现它?

id | categoryid
------------------
27 | Apple

最佳答案

您可以将 $this->retrieveSQL = ... 的 SQL 更改为

if (!is_number($catid)) {
$this->retrieveSQL = "select * from items i, item_category_lookup l, category j where livedate < '" . $this->currentdate . "' and i.active = " . $this->showApproved . " and i.id = l.itemid and j.id = l.categroyid and j.categoryid = "$catid" order by i.livedate desc limit " . $this->startRow . "," . $this->numRows;
}

关于php - 如何使用 PHP 和 MySQL 将 URL 类别编号更改为单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16489219/

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