javivilchis Posted March 29, 2009 Share Posted March 29, 2009 Hello all, I am stuck with creating a function that creates paging for categories of my gallery. Please help, this is what I have: //this file is the one that generates the categories in the layout the error i'm getting is this: Fatal error: Call to undefined function: getcatslist() in /home/javivi2/public_html/wsgallery/gallery.php on line 15 this is what gallery.php looks like: include("include/ws_Core.class.php"); $ws = $_GET['ws']; switch($ws){ default: include("include/session.php"); include ("header.php"); $t->readFileIntoString(TEMPLATE.'gallery.tpl',$wspage); $t->setTemplateString($wspage); global $database; $p = new wsCore; $p->GetCatsList(); if(count($p->getcatslist)>0){ foreach($p->getcatslist as $cval){ $listc .= '<br><a href="?cid='.$cval['c_id'].'">'.$cval['c_name'].'</a> '; } } $p->Paging(); $cid = intval($_GET['cid']); $p->LatestImgCat($cid); if(count($p->latestimgcat) >0){ //get all thumbs for this cat //this is line 15 $p->GetCatsList(); any suggestions? // ws_core.php has the function called Paging This is the ws_Core.class.php this is where the $limit is declared: <?php class wsCore{ var $values = array(); function GetPics($limit1, $limit2){ global $database; $q = "SELECT *" ."FROM ".TBL_PICTURE." ORDER BY p_name LIMIT ".(int)$limit1.", ".(int)$limit2.""; $result = $database->query($q); if($nrows = $database->sql_numrows($result) >0){ $c =0; while($row = $database->sql_fetchrow($result)){ foreach($row as $key => $val) { $this->getpics[$c][$key] = $val; } $c++; } return true; }else{ return false; } }//EOF function GetPic($pid){ global $database; $q = "SELECT * " ."FROM ".TBL_PICTURE." WHERE p_id='".(int)$pid."'"; $result = $database->query($q); if($nrows = $database->sql_numrows($result) >0){ $c =0; while($row = $database->sql_fetchrow($result)){ foreach($row as $key => $val) { $this->getpic[$c][$key] = $val; } $c++; } return true; }else{ return false; } }//EOF function GetCats($limit1, $limit2){ global $database; $q = "SELECT *" ."FROM ".TBL_CATEGORY." ORDER BY c_name LIMIT ".(int)$limit1.", ".(int)$limit2.""; $result = $database->query($q); if($nrows = $database->sql_numrows($result) >0){ $c =0; $this->getcatsnbr = 1; while($row = $database->sql_fetchrow($result)){ foreach($row as $key => $val) { $this->getcats[$c][$key] = $val; } $c++; } return true; }else{ return false; } }//EOF function Paging(){ global $database; $sql = "SELECT count(c_id) FROM ws_category "; $retval = mysql_query( $sql ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } $row = mysql_fetch_array($retval, MYSQL_NUM ); $rec_count = $row[0]; if( isset($_GET{'page'} ) ) { $page = $_GET{'page'} + 1; } else { $page = 0; $offset = 0; } $left_rec = $rec_count - ($page * $rec_limit); $sql = "SELECT c_id". "FROM ws_category ". "LIMIT $offset, $rec_limit"; $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "EMP ID :{$row['cp_id']} <br>"; } if( $page > 0 ) { $last = $page - 2; echo "<a href=\"$_PHP_SELF?page=$last\">Last 10 Records</a> |"; echo "<a href=\"$_PHP_SELF?page=$page\">Next 10 Records</a>"; } else if( $page == 0 ) { echo "<a href=\"$_PHP_SELF?page=$page\">Next 10 Records</a>"; } else if( $left_rec < $rec_limit ) { $last = $page - 2; echo "<a href=\"$_PHP_SELF?page=$last\">Last 10 Records</a>"; } //EOF function GetCatsList(){ global $database; $q = "SELECT *" ."FROM ".TBL_CATEGORY." ORDER BY c_name"; $result = $database->query($q); if($nrows = $database->sql_numrows($result) >0){ $c =0; while($row = $database->sql_fetchrow($result)){ foreach($row as $key => $val) { $this->getcatslist[$c][$key] = $val; } $c++; } return true; }else{ return false; } }//EOF function GetCat($cid){ global $database; $sql = sprintf("SELECT * FROM %s WHERE c_id='%d'", TBL_CATEGORY, (int)$cid); $result = $database->query($sql); if($nrows = $database->sql_numrows($result) >0){ $c =0; while($row = $database->sql_fetchrow($result)){ foreach($row as $key => $val) { $this->getcat[$c][$key] = $val; } $c++; } return true; }else{ return false; } }//EOF function RandomCat(){ global $database; $sql = sprintf("SELECT s.*, t.* FROM %s s, %s t WHERE s.c_id=t.c_id ORDER BY RAND() LIMIT 1", TBL_CATEGORY, TBL_PICTURE); $result = $database->query($sql); if($nrows = $database->sql_numrows($result) >0){ $c =0; while($row = $database->sql_fetchrow($result)){ foreach($row as $key => $val) { $this->randomcat[$c][$key] = $val; } $c++; } return true; }else{ return false; } }//EOF function RandomPic($cid){ global $database; $q = "SELECT *" ."FROM ".TBL_PICTURE." WHERE c_id='".(int)$cid."' ORDER BY RAND() LIMIT 1"; $result = $database->query($q); if($nrows = $database->sql_numrows($result) >0){ $c =0; while($row = $database->sql_fetchrow($result)){ foreach($row as $key => $val) { $this->randompic[$c][$key] = $val; } $c++; } return true; }else{ return false; } }//EOF function GetThumbs($cid){ global $database; $q = "SELECT p_id, p_name, thumb_url " ."FROM ".TBL_PICTURE." WHERE c_id='".(int)$cid."' ORDER BY p_name ASC"; $result = $database->query($q); if($nrows = $database->sql_numrows($result) >0){ $c =0; while($row = $database->sql_fetchrow($result)){ foreach($row as $key => $val) { $this->getthumbs[$c][$key] = $val; } $c++; } return true; }else{ return false; } }//EOF function LatestImgCat($cid){ global $database; if(empty($cid)){ $andwhere =""; }else{ $andwhere = "AND t.c_id='".(int)$cid."'"; } $sql = sprintf("SELECT s.*, t.* FROM %s s, %s t WHERE s.c_id=t.c_id ".$andwhere." ORDER BY t.time DESC LIMIT 0,1", TBL_CATEGORY, TBL_PICTURE); $result = $database->query($sql); if($nrows = $database->sql_numrows($result) >0){ $c =0; while($row = $database->sql_fetchrow($result)){ foreach($row as $key => $val) { $this->latestimgcat[$c][$key] = $val; } $c++; } return true; }else{ return false; } } function Paging($page, $totalcount, $perpage, $start){ $eu = ($start - 0); $this1 = $eu + $perpage; $back = $eu - $perpage; $next = $eu + $perpage; $paging =''; $showeachside = 10; $eitherside = ($showeachside * $perpage); if($start+1 > $eitherside)$paging .="<a href='".$page."'>[First]</a> .... "; $y =0; $pg=1; for($y=0;$y<$totalcount;$y+=$perpage) { $class=($y==$start)?"pageselected":""; if(($y > ($start - $eitherside)) && ($y < ($start + $eitherside))) { if($y <> $eu){ $paging .= '<a href="'.$page.'&start='.$y.'" class="'.$class.'" ><span class="paging">'.$pg.'</span></a>'; } else{ $paging .= '<b>'.$pg.'</b>'; } } $pg++; } if(($start+$eitherside)<$totalcount)$paging .=" .... "; if($this1 < $totalcount) { $paging .= "<a href='".$page."&start=$next'>Next</a>";} if($back >=0) { $paging .= "<a href='".$page."&start=$back'>Prev</a>"; } $this->ws_page = $eu; $this->ws_paging = $paging; } }//EOF function shortenTxt($wstxt, $chars=125) { $wstxt = $wstxt." "; $wstxt = substr($wstxt,0,$chars); $wstxt = substr($wstxt,0,strrpos($wstxt,' ')); return $wstxt; }//EOF }//EOC ?> Quote Link to comment https://forums.phpfreaks.com/topic/151648-help-with-paging/ Share on other sites More sharing options...
dadamssg Posted March 29, 2009 Share Posted March 29, 2009 try copying that function from the ws_core.class.php script into the that first page and see what happens Quote Link to comment https://forums.phpfreaks.com/topic/151648-help-with-paging/#findComment-796388 Share on other sites More sharing options...
javivilchis Posted March 30, 2009 Author Share Posted March 30, 2009 Parse error: syntax error, unexpected T_CASE in /home/javivi2/public_html/wsgallery/gallery.php on line 119 line 119: case "viewpic": include("include/session.php"); include ("header.php"); $t->readFileIntoString(TEMPLATE.'view.tpl',$wspage); $t->setTemplateString($wspage); global $database; $p = new wsCore; $p->GetCatsList(); if(count($p->getcatslist)>0){ foreach($p->getcatslist as $cval){ $listc .= '<a href="?cid='.$cval['c_id'].'">'.$cval['c_name'].'</a> | '; } } $pid = intval($_REQUEST['pid']); $p->GetPic($pid); //get all thumbs for this cat $p->GetThumbs($p->getpic[0]['c_id']); if(count($p->getthumbs) >0){ foreach($p->getthumbs as $pval){ if($pval['p_id'] == $p->getpic[0]['p_id']){ $elsel = 'ws-thumbs-sel'; }else{ $elsel = 'ws-thumbs'; } $thumbs .= '<a href="?ws=viewpic&pid='.$pval['p_id'].'" title="View details"><div class="'.$elsel.'"><img src="pictures/'.$pval['thumb_url'].'" border="0"></div></a>'; line:151: } line:152:} Quote Link to comment https://forums.phpfreaks.com/topic/151648-help-with-paging/#findComment-796493 Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 Please use tags, and don't post all of your code like that, only relevant. Quote Link to comment https://forums.phpfreaks.com/topic/151648-help-with-paging/#findComment-796495 Share on other sites More sharing options...
javivilchis Posted March 30, 2009 Author Share Posted March 30, 2009 sorry about that, i'm new to this forum... i'll follow the rules... thanks, Quote Link to comment https://forums.phpfreaks.com/topic/151648-help-with-paging/#findComment-796564 Share on other sites More sharing options...
javivilchis Posted March 30, 2009 Author Share Posted March 30, 2009 this is the section that throws the error when I place the function to the gallery.php case "viewpic": include("include/session.php"); include ("header.php"); $t->readFileIntoString(TEMPLATE.'view.tpl',$wspage); $t->setTemplateString($wspage); global $database; $p = new wsCore; $p->GetCatsList(); if(count($p->getcatslist)>0){ foreach($p->getcatslist as $cval){ $listc .= '<a href="?cid='.$cval['c_id'].'">'.$cval['c_name'].'</a> | '; } } Quote Link to comment https://forums.phpfreaks.com/topic/151648-help-with-paging/#findComment-796568 Share on other sites More sharing options...
javivilchis Posted April 1, 2009 Author Share Posted April 1, 2009 is there anyone that can help. Please :( :( Quote Link to comment https://forums.phpfreaks.com/topic/151648-help-with-paging/#findComment-798337 Share on other sites More sharing options...
Maq Posted April 1, 2009 Share Posted April 1, 2009 And you're positive GetCatsList() is a method of the class wsCore? Are you properly using the switch statement, breaking in and out? You may want to read switch. Besides that I'm not really sure, cause you're giving us 2 separate errors with different code. Quote Link to comment https://forums.phpfreaks.com/topic/151648-help-with-paging/#findComment-798349 Share on other sites More sharing options...
javivilchis Posted April 1, 2009 Author Share Posted April 1, 2009 thank you for responding.. this is the function I have to create pages of my categories: function Paging($page, $totalcount, $perpage, $start){ $eu = ($start - 0); $this1 = $eu + $perpage; $back = $eu - $perpage; $next = $eu + $perpage; $paging =''; $showeachside = 10; $eitherside = ($showeachside * $perpage); if($start+1 > $eitherside)$paging .="<a href='".$page."'>[First]</a> .... "; $y =0; $pg=1; for($y=0;$y<$totalcount;$y+=$perpage) { $class=($y==$start)?"pageselected":""; if(($y > ($start - $eitherside)) && ($y < ($start + $eitherside))) { if($y <> $eu){ $paging .= '<a href="'.$page.'&start='.$y.'" class="'.$class.'" ><span class="paging">'.$pg.'</span></a>'; } else{ $paging .= '<b>'.$pg.'</b>'; } } $pg++; } if(($start+$eitherside)<$totalcount)$paging .=" .... "; if($this1 < $totalcount) { $paging .= "<a href='".$page."&start=$next'>Next</a>";} if($back >=0) { $paging .= "<a href='".$page."&start=$back'>Prev</a>"; } $this->ws_page = $eu; $this->ws_paging = $paging; } } how do I incorporate this to my gallery.php where I use switch case.? Quote Link to comment https://forums.phpfreaks.com/topic/151648-help-with-paging/#findComment-798541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.