mysql - Previous/next button in PHP -
i´m pretty entirely new php, please bear me.
i´m trying build website running on cms called core. i'm trying make previous/next buttons cycle through tags rather entries. tags stored in database core_tags. each tag has own tag_id, number. i've tried changing excisting code thep previous/next buttons, keeps giving me 'warning: mysql_fetch_array() expects parameter 1 resource, null given in /home/core/functions/get_entry.php on line 50'.'
any 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.* core_pages p 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 p.page_title = $id"); } if($type == "entry") { // queries dbase $data_tags = mysql_query("select entry_id,entry_title core_entries entry_show = 1 order 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 view first entry if($value == reset($array)){ $return['prev'] = end($array); $return['next'] = $array[$index + 1]; //if user clicked view 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.* core_entries e e.entry_id = $id , e.entry_show = 1"); $entry_clicks = 0; if(@mysql_num_rows($data) < 1) { die("invalid id, no entry 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 core_entry2tag e2t 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 core_tags t 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 e.entry_id = $id"); } if($isperma) { echo "<a class=\"index-link\" href=\"$http\">back index</a>"; } ?>
you have not defined $data_entries, before using here:
while($tmparray = mysql_fetch_array($data_entries,mysql_assoc)){ array_push($navarr,$tmparray['entry_id']); }
that why descriptive error message. did mean use $data_tags?
Comments
Post a Comment