Jump to content

Help with paging


javivilchis

Recommended Posts

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

 

?>

 

Link to comment
Share on other sites

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:}

 

Link to comment
Share on other sites

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> | ';
  }
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.