doudieheng5322 2014-04-22 10:34
浏览 55

PHP中的上一个/下一个按钮

I´m pretty much entirely new to PHP, so please bear with me.

I´m trying to build a website running on a cms called Core. I'm trying to make it so that the previous/next buttons cycle through tags rather than entries. Tags are stored in a database as core_tags. Each tag has it own tag_id, which is a number. I've tried changing the excisting code for thep previous/next buttons, but it keeps giving me 'Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/core/functions/get_entry.php on line 50'.'

Any help would be greatly appreciated.

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>";
}
?>
  • 写回答

3条回答 默认 最新

  • doujiene2845 2014-04-22 10:39
    关注

    You have not defined $data_entries, before using it here:

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

    That is why you get the very descriptive error message. Did you mean to use $data_tags?

    评论

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图