Author Topic: SOLVED - {PAGING} problem on an additional page  (Read 5642 times)

0 Members and 1 Guest are viewing this topic.

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
SOLVED - {PAGING} problem on an additional page
« on: December 19, 2008, 09:53:26 AM »
Hello,

I have an additional page with all the images of my gallery from all the categories. I call it: ImagesList.

I already have the imageslist_sort_dropdown_form and it working very fine.

But I have a problem with: {paging} and {paging_stats}. It doesn't work at all.

Because I am not a programmer, I tried to see how the paging on the category page works. This is my code:

Code: [Select]
<?php
$main_template 
'videolist';


define('GET_CACHES'1);
define('ROOT_PATH''./');
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
include(
ROOT_PATH.'includes/page_header.php');
include(
ROOT_PATH.'includes/stats.php');



//-----------------------------------------VideoList--------------------------------------------------------------------
$additional_sql "";
  
$additional_sql_array = array();
  if (isset(
$additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
      foreach (
$additional_user_fields as $key => $val) {
          
$additional_sql ", u." $key;
          
$additional_sql_array[] = $key;
      }
  }
$additional_sql "";
if (!empty(
$additional_image_fields)) {
  foreach (
$additional_image_fields as $key => $val) {
    
$additional_sql .= ", i.".$key;
  }
}
 



//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$order_by "image_hits $sort_order";
  
$sql "SELECT COUNT(image_id) AS images
            FROM ("
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
            WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN ("
.get_auth_cat_sql("auth_viewimage").") 
            
            "
;
   
$result $site_db->query_firstrow($sql);
   
$num_images $result['images'];
   
$site_db->free_result();
   
$num_rows_all = (isset($num_images)) ? $num_images 0;
   
$link_arg $site_sess->url(ROOT_PATH."videolist.php?action=hits");
   include_once(
ROOT_PATH.'includes/paging.php');

   if (
$num_images >= $max_picture) { 
      
$num_images $max_picture
   }
   else { 
        
$num_images == $result['images']; 
   }

   
$getpaging = new Paging($page$picture_per_page$num_images$link_arg);
   
$offset $getpaging->get_offset();
   
$site_template->register_vars(array(
      
"paging" => $getpaging->get_paging(),
      
"paging_stats" => $getpaging->get_paging_stats()
   ));

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++






$sql "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_speler, i.image_youtube, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, i.image_postcards".$additional_sql.", c.cat_name".get_user_table_field(", u.""user_name").get_user_table_field(", u.""user_email")."
        FROM ("
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
        LEFT JOIN "
.USERS_TABLE." u ON (".get_user_table_field("u.""user_id")." = i.user_id) 
        WHERE i.image_active = 1 AND i.cat_id IN ("
.get_auth_cat_sql("auth_viewcat").")
GROUP BY i.image_id
ORDER BY "
.$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
        LIMIT 
$offset$perpage";


   
$result $site_db->query($sql); 
$num_rows $site_db->get_numrows($result);





if (!
$num_rows)  { 
   
$videolist "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\"><tr><td>".$lang['geen_events']."</td></tr>"

else  {
    
$videolist "<table class=\"head2\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
    <tr>
    <td></td>
    <td><b>Thumb</b></td>
    <td><b>Naam</b></td>
    <td><b>Speler</b></td>
    <td><b>Categorie</b></td>
    <td><b>Duur</b></td>
    <td><b>Bekeken</b></td>
    </tr>
    "
;
   
   
   
$i 01;
   while (
$image_row $site_db->fetch_array($result)){  
  

   
   
$videolist .= "<tr>

   <td>"
.$i++."</td>
   <td><a href=\""
.$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_row['image_id'])."\"><img src=\"data/thumbnails/".$image_row['cat_id']."/".$image_row['image_thumb_file']."\" width=\"48\" height=\"32\" border=\"0\"/></td>
   <td><a href=\""
.$site_sess->url(ROOT_PATH."details.php?image_id=".$image_row['image_id'])."\">".$image_row['image_name']."</a></td>
      <td>"
.$image_row['image_speler']."</a></td>

   
   <td><a href=\""
.$site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$image_row['cat_id'])."\">".format_text($cat_cache[$image_row['cat_id']]['cat_name'])."</a></td>
   
   <td><b>"
.$image_row['image_duration']."</b></td>
   <td>"
.$image_row['image_hits']."</td>
   
   
</td></tr>

   "
;                   
}      

  
$videolist .= "</table>\n";
  
$site_template->register_vars("videolist"$videolist); 
unset(
$videolist);
//---------------------------------------------------------------------------- 
  
 

 
 

  
//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator']."Videolist pagina"."</span>";



//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------





$site_template->register_vars(array(
  
"clickstream" => $clickstream,
  
"user_name" => $user_row[$user_table_fields['user_id']],
  
"lang_title_videolist_images" => $lang['title_videolist_images'],
   
"cat_name" => format_text($cat_cache[$cat_id]['cat_name'], 2),

));
$site_template->print_template($site_template->parse_template($main_template));

include(
ROOT_PATH.'includes/page_footer.php');

?>



Could anyone help me please? I really gave it a try for more that 6 hours.


I appreciate any help,

« Last Edit: December 21, 2008, 01:07:30 PM by cruxy »

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: {PAGING} problem on an additional page
« Reply #1 on: December 20, 2008, 12:30:08 AM »
Hi guys, I got it to work :D, but I still have a small problem with the paging counter.

I will explain:

If you have for example 4 pages of 10 images, start every page with the number 1 to 10, instead of the second one start with 10 to 20 and the 3de one from 31 to 40.

How can I solve this small issue?

I am using this code for the paging counter:

Code: [Select]
for ($i = 0 ; $i < $num_images; $i++)
And then


Code: [Select]
<td>".$i++."<td>

I found out also how to count the images of the last page with code:

Code: [Select]
$image_counter = $num_images-(($i+1+($page-1)*$perpage)-1);
I really need some help. Do you have some minutes for me please?

Can someone help me please?


Many thanks in advance,

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: {PAGING} problem on an additional page
« Reply #2 on: December 20, 2008, 12:56:11 AM »
Please show the code you have.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: {PAGING} problem on an additional page
« Reply #3 on: December 20, 2008, 01:00:36 AM »
Here you are Vano. Many thanks in advance:

Code: [Select]
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: VideoList.php                                       *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.6                                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/


$templates_used 'videolist';
$main_template 'videolist';

define('GET_CACHES'1);
define('ROOT_PATH''./');
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
$user_access get_permission();
include(
ROOT_PATH.'includes/page_header.php');
include(
ROOT_PATH.'includes/stats.php');


//----------------------------
//---- Set user per page -----
//----------------------------
$picture_per_page $perpage;
$sort_order 'DESC';
$max_picture 10000;      //for more pictures change this value

   
$sql "SELECT COUNT(image_id) AS images
            FROM ("
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
            WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN ("
.get_auth_cat_sql("auth_viewimage").")
            "
;
            
          
   
$result $site_db->query_firstrow($sql);
   
$num_images $result['images'];
   
$site_db->free_result();
   
$num_rows_all = (isset($num_images)) ? $num_images 0;
   
$link_arg $site_sess->url(ROOT_PATH."videolist.php");
   

   include_once(
ROOT_PATH.'includes/paging.php');
   if (
$num_images >= $max_picture) { 
      
$num_images $max_picture
   }
   else { 
        
$num_images == $result['images']; 
   }

   
$getpaging = new Paging($page$perpage$num_images$link_arg);


   
$offset $getpaging->get_offset();
   
$site_template->register_vars(array(
      
"paging" => $getpaging->get_paging(),
      
"paging_stats" => $getpaging->get_paging_stats()
   ));


  
$sql "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_speler, i.image_duration, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_last_view, i.image_last_view_who,i.image_hits".$additional_sql.", c.cat_name
         FROM ("
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
        WHERE  i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN ("
.get_auth_cat_sql("auth_viewimage").")
        
        GROUP BY i.image_id
ORDER BY "
.$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
        LIMIT 
$offset$perpage";        
  
$result $site_db->query($sql); 
$num_rows $site_db->get_numrows($result);


if (!
$num_rows)  { 
   
$videolist "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\"><tr><td>".$lang['geen_events']."</td></tr>"

else  {
    
$videolist "<table class=\"head2\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
    <tr>
    <td></td>
    <td><b>Thumb</b></td>
    <td><b>Naam</b></td>
    <td><b>Speler</b></td>
    <td><b>Categorie</b></td>
    <td><b>Duur</b></td>
    <td><b>Bekeken</b></td>
    </tr>
    "
;
   

 
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   
$page ceil($num_images $perpage);
   
$ii 1;
   for (
$i $i $num_images$i++)
   
   while (
$image_row $site_db->fetch_array($result)){  
  
   
$image_counter $num_images-(($i+1+($page-1)*$perpage)-1);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   

   
   
$videolist .= "<tr>

   <td>"
.$i++."</td>
   <td><a href=\""
.$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_row['image_id'])."\"><img src=\"data/thumbnails/".$image_row['cat_id']."/".$image_row['image_thumb_file']."\" width=\"48\" height=\"32\" border=\"0\"/></td>
   <td><a href=\""
.$site_sess->url(ROOT_PATH."details.php?image_id=".$image_row['image_id'])."\">".$image_row['image_name']."</a></td>
      <td>"
.$image_row['image_speler']."</a></td>

   
   <td><a href=\""
.$site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$image_row['cat_id'])."\">".format_text($cat_cache[$image_row['cat_id']]['cat_name'])."</a></td>
   
   <td><b>"
.$image_row['image_duration']."</b></td>
   <td>"
.$image_row['image_hits']."</td>
   
   
</td></tr>

   "
;                   
}      

  
$videolist .= "</table>\n";
  
$site_template->register_vars("videolist"$videolist); 
unset(
$videolist);
//---------------------------------------------------------------------------- 
 

  //-----------------------------------------------------
  //--- Clickstream -------------------------------------
  //-----------------------------------------------------
  
$clickstream "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'];
  
$clickstream .= $lang['videolist'];
  
$clickstream .= $config['category_separator'].$lang['lang_toplist_page'].$page."</span>";

//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
 
$site_template->register_vars(array(
 
"image_counter" => $image_counter,
 
"msg" => $msg,
 
"lang_no_videolist" => $lang['no_videolist'],
 
"lang_videolist" => $lang['videolist'],

 
"clickstream" => $clickstream,
 
));
 
$site_template->print_template($site_template->parse_template($main_template));
 include(
ROOT_PATH.'includes/page_footer.php');
?>
« Last Edit: December 20, 2008, 04:16:22 PM by cruxy »

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: {PAGING} problem on an additional page
« Reply #4 on: December 20, 2008, 04:18:16 PM »
Hi V@no. I just updated my code. I hope you can help me solving this issue.

PS: As usual, I try always to learn from you :wink:

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: {PAGING} problem on an additional page
« Reply #5 on: December 20, 2008, 08:30:03 PM »
try this:
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: VideoList.php                                        *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.6                                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) fur weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/


$templates_used 'videolist';
$main_template 'videolist';

define('GET_CACHES'1);
define('ROOT_PATH''./');
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
$user_access get_permission();
include(
ROOT_PATH.'includes/page_header.php');
include(
ROOT_PATH.'includes/stats.php');


//----------------------------
//---- Set user per page -----
//----------------------------
$picture_per_page $perpage;
$sort_order 'DESC';
$max_picture 10000;      //for more pictures change this value

$sql "SELECT COUNT(image_id) AS images
        FROM "
.IMAGES_TABLE."
        WHERE image_active = 1 AND cat_id IN ("
.get_auth_cat_sql("auth_viewimage").")";


$result $site_db->query_firstrow($sql);
#$num_images = $result['images']; ### it will be defined later
$site_db->free_result();
#$num_rows_all = (isset($num_images)) ? $num_images : 0; ### not used at all
$link_arg $site_sess->url(ROOT_PATH."videolist.php");


include_once(
ROOT_PATH.'includes/paging.php');
if (
$num_images >= $max_picture) {
  
$num_images $max_picture;
}
else {
  
$num_images == $result['images'];
}

$getpaging = new Paging($page$perpage$num_images$link_arg);


$offset $getpaging->get_offset();
$site_template->register_vars(array(
  
"paging" => $getpaging->get_paging(),
  
"paging_stats" => $getpaging->get_paging_stats()
));


$sql "SELECT image_id, cat_id, user_id, image_name, image_description, image_speler, image_duration, image_keywords, image_date, image_active, image_media_file, image_thumb_file, image_download_url, image_allow_comments, image_comments, image_downloads, image_votes, image_rating, image_last_view, image_last_view_who,image_hits".$additional_sql."
        FROM "
.IMAGES_TABLE."
        WHERE  image_active = 1 AND cat_id IN ("
.get_auth_cat_sql("auth_viewimage").")
        ORDER BY "
.$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
        LIMIT 
$offset$perpage";
$result $site_db->query($sql);
$num_rows $site_db->get_numrows($result);


if (!
$num_rows)  {
   
$videolist "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\"><tr><td>".$lang['geen_events']."</td></tr>";
}
else {
  
$videolist "<table class=\"head2\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
  <tr>
  <td></td>
  <td><b>Thumb</b></td>
  <td><b>Naam</b></td>
  <td><b>Speler</b></td>
  <td><b>Categorie</b></td>
  <td><b>Duur</b></td>
  <td><b>Bekeken</b></td>
  </tr>
  "
;



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  $page = ceil($num_images / $perpage); ### $page is already present
#  $ii = 1; ### this line does nothing
#  for ($i = 1 ; $i < $num_images; $i++) ### don't need any loops
  
$i 0;
#  $i = $offset; ### use this line instead, to continue count based on page (is eaqual to $i=$page*$perpage-$perpage)
  
$image_counter 0;
  while (
$image_row $site_db->fetch_array($result)){

#   $image_counter = $num_images-(($i+1+($page-1)*$perpage)-1); ### don't need calculate anything, we'll count it as we go.
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
$image_counter++; ### since you don't need this number BEFORE list generated, count them during the list generation.
    
$image_url $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_row['image_id']); ### if you need generate more then one link, it's better save it into a variable, less server load this way
### ++$i instead of $i++ because we are one number behind in the count (started with 0)
### use get_file_path() function for the image location address. This way you don't need modify the code if you decided move images to another location or protect them with a antileech script.
    
$videolist .= "<tr>
      <td>"
.++$i."</td>
      <td><a href=\""
.$image_url."\"><img src=\"".get_file_path($image_row['image_thumb_file'], "thumb"$image_row['cat_id'], 01)."\" width=\"48\" height=\"32\" border=\"0\"/></td>
      <td><a href=\""
.$image_url."\">".$image_row['image_name']."</a></td>
      <td>"
.$image_row['image_speler']."</a></td>
      <td><a href=\""
.$site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$image_row['cat_id'])."\">".format_text($cat_cache[$image_row['cat_id']]['cat_name'])."</a></td>
      td><b>"
.$image_row['image_duration']."</b></td>
      <td>"
.$image_row['image_hits']."</td>
      </td></tr>
    "
;
  }
}
  
$videolist .= "</table>\n";

$site_template->register_vars("videolist"$videolist);
unset(
$videolist);
//----------------------------------------------------------------------------


//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'];
$clickstream .= $lang['videolist'];
$clickstream .= $config['category_separator'].$lang['lang_toplist_page'].$page."</span>";

//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
  
"image_counter" => $image_counter,
  
"msg" => $msg,
  
"lang_no_videolist" => $lang['no_videolist'],
  
"lang_videolist" => $lang['videolist'],
  
  
"clickstream" => $clickstream,
));
$site_template->print_template($site_template->parse_template($main_template));
include(
ROOT_PATH.'includes/page_footer.php');
?>


See my comments marked by ###
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: {PAGING} problem on an additional page
« Reply #6 on: December 20, 2008, 09:10:06 PM »
Hi V@no, thanks for your help  :D

I am getting this error:

Fatal error: Maximum execution time of 30 seconds exceeded in /hsphere/local/home/******/******videolist.php on line 109

In the line 109 I have this:  $i = 0;


Here is the link of the site:

http://www.jogabonito.nl/videolist.php



Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: {PAGING} problem on an additional page
« Reply #7 on: December 20, 2008, 09:18:42 PM »
Hi V@no. You are great. It is working.

I just deleted some lines.

I thank you very much :D

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: {PAGING} problem on an additional page
« Reply #8 on: December 21, 2008, 09:24:21 AM »
Hi V@no, I thanked you about your help, but I forgot to thank you about the tutorial :wink:

I learned again something new from you.