mysql PHP中的Previous/Next按钮

wn9m85ua  于 2023-06-21  发布在  Mysql
关注(0)|答案(3)|浏览(165)

我对PHP几乎完全是新手,所以请容忍我。
我试图建立一个网站上运行的CMS称为核心。我试图使它,使上一个/下一个按钮循环通过标签,而不是条目。标签作为core_tags存储在数据库中。每个标签都有自己的tag_id,这是一个数字。我试过改变前一个/下一个按钮的代码,但它一直给我“警告:mysql_fetch_array()expects parameter 1 to be resource,null given in/home/core/functions/get_entry.php on line 50'.'
任何帮助将不胜感激。
Get_entry.php:

<?php

$b = $_SERVER['REQUEST_URI'];

if($entry) {
    $b = substr($b,0,strrpos($b,"/")) . "/core/";
    $id = $entry;
    $isPerma = true;
} else {
    $b = substr($b,0,mb_strrpos($b,"/core/")+6);
    $id = $_REQUEST["id"];
}

$root = $_SERVER['DOCUMENT_ROOT'] . $b;
$http = "http://" . $_SERVER['HTTP_HOST'] . substr($b,0,strlen($b)-5);

require_once($root . "user/configuration.php");
require_once($root . "themes/".$theme."/configuration.php");
require_once($root . "functions/session.php");

if(is_numeric($id)) {
    $type = "entry";
} else {
    $type = "page";
}

$id = secure($id);

if($type == "page") {
    $data = mysql_query("SELECT p.* FROM core_pages p WHERE p.page_title = \"$id\"");
    $page_clicks = 0;
    while($p = mysql_fetch_array($data)) {
        $url = $p["page_url"];
        $path = $root . "user/pages/" . $url;
        $page_clicks = $p['hits']+1;
        require($path);
    }

    mysql_query("UPDATE core_pages p SET
    p.hits = $page_clicks
    WHERE p.page_title = $id");
}

if($type == "entry") {

// queries the dbase
        $data_tags = mysql_query("SELECT entry_id,entry_title FROM core_entries WHERE entry_show = 1 ORDER BY entry_position DESC") or die(mysql_error());

    $navArr=array();
    while($tmparray = mysql_fetch_array($data_entries,MYSQL_ASSOC)){
                array_push($navArr,$tmparray['entry_id']);
        }

    function array_next_previous($array, $value) {
    $index = array_search($value,$array);

    //if user clicked to view the very first entry
    if($value == reset($array)){
    $return['prev'] = end($array);
    $return['next'] = $array[$index + 1];
    //if user clicked to view the very last entry
    }else if($value == end($array)){
    $return['prev'] = $array[$index - 1];
    reset($array);
    $return['next'] = current($array);
    }else{
        $return['next'] = $array[$index + 1];
        $return['prev'] = $array[$index - 1];
    }
                return $return;
    }

    $data = mysql_query("SELECT e.* FROM core_entries e WHERE e.entry_id = $id AND e.entry_show = 1");
    $entry_clicks = 0;
    if(@mysql_num_rows($data) < 1) {
        die("Invalid id, no entry to be shown");
    }
    while($e = mysql_fetch_array($data)) {
        $nextPrevProject = array_next_previous($navArr,$id); 
        $entry_id       = $e['entry_id'];
        $entry_title    = $e['entry_title'];
        // DATE
        $t              = $e["entry_date"];
        $y              = substr($t,0,4);
        $m              = substr($t,5,2);
        $d              = substr($t,8,2);
        $entry_date     = date($date_format,mktime(0,0,0,$m,$d,$y));
        $entry_text     = $e['entry_text'];
        $entry_extra1   = $e['entry_extra1'];
        $entry_extra2   = $e['entry_extra2'];
        $entry_client   = $e['entry_client'];
        $entry_position = $e['entry_position'];
        $entry_hits     = $e['hits']+1;
        $entry_new      = $e['entry_new'];

        if($entry_new == 1) {
            $isNew = true;
        } else {
            $isNew = false;
        }

        if($nice_permalinks) {
            $entry_perma = "$http".$entry_id;
        } else {
            $entry_perma = "$http"."?entry=$entry_id";
        }

        $data_e2t = @mysql_query("SELECT e2t.tag_id FROM core_entry2tag e2t WHERE e2t.entry_id = $entry_id");

        $tag_str = "";

            while($e2t = @mysql_fetch_array($data_e2t)) {
                $tag_id = $e2t["tag_id"];
                $data_tags = @mysql_query("SELECT t.tag_text FROM core_tags t WHERE t.tag_id = $tag_id");
                    while($t = @mysql_fetch_array($data_tags)) {
                        $tag_text = $t["tag_text"];
                        $tag_str = $tag_str . "<a class=\"tag-link\" name=\"tag".$tag_id."\" href=\"#tag-"._encode($tag_text)."\">".$tag_text."</a>".$separator_tags;
                    }
            }

            $entry_tags = substr($tag_str,0,strlen($tag_str)-strlen($separator_tags));

        $layout_path = $root . "user/uploads/" . treat_string($entry_title) . "/layout.php";
        if(is_file($layout_path) && (@filesize($layout_path) > 0)) {
            require($layout_path);
        } else {
            require($theme_path . "parts/entry.php");
        }
    }

    mysql_query("UPDATE core_entries e SET
    e.hits = $entry_hits
    WHERE e.entry_id = $id");

}

if($isPerma) {
echo "<a class=\"index-link\" href=\"$http\">back to index</a>";
}
?>
3gtaxfhh

3gtaxfhh1#

在这里使用之前,您尚未定义$data_entries:

while($tmparray = mysql_fetch_array($data_entries,MYSQL_ASSOC)){
                array_push($navArr,$tmparray['entry_id']);
        }

这就是为什么你得到非常描述性的错误消息。你的意思是使用$data_tags吗?

t5zmwmid

t5zmwmid2#

用途:"SELECT p.* FROM core_pages p WHERE p.page_title = '".$id."'
注意:mysql_connect不是sql注入保存。如果使用mysql_connect,请更改为PDO。

uujelgoq

uujelgoq3#

如果$data_entries在第50行没有定义,则mysql_fetch_array返回一个null值的异常。
尝试将$tmparray = mysql_fetch_array($data_entries,MYSQL_ASSOC)更改为$tmparray = mysql_fetch_array($data_tags,MYSQL_ASSOC)
希望这个有帮助!

相关问题