0

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

要查看一个类别,URL 是,出于 SEO 原因www.example.com/index.php?catid=27,我想将其更改为。www.example.com/index.php?catid=apple我知道我可以用 .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
4

2 回答 2

0

试试这个: URL 示例:www.example.com/index.php?catid=27-apple

if ( isset( $_REQUEST['catid'] ) ) {
    $catSEO = explode( '-', $_REQUEST['catid'] );
}
$catid = is_numeric( $catSEO[0] ) ? $catSEO:0;
于 2013-05-10T19:27:46.880 回答
0

You might change the SQL of $this->retrieveSQL = ... into

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;
}
于 2013-05-10T19:20:58.897 回答