PHP Forums Archive

Change number of items per page MyPagina

Tags: myPagina, items per page

telconstar99 posted on 2008-04-22 10:00:33 #

Hello,

I'm using the MyPagina class. I'd like to change the number of items per page I'm displaying. Right now I am simply displaying the default 4 items per page.

This is what my code looks like:

$myGallery = new MyPagina;
$myGallery->sql = "SELECT * FROM galleries WHERE category LIKE '%".$category."%' ORDER BY date DESC";
$result = $myGallery->get_page_result();
$myGallery->rows_on_page=6;
$num_rows = $myGallery->get_page_num_rows();
$nav_links = $myGallery->navigation(" | ", "currentStyle");
$nav_info = $myGallery->page_info("to");
$simple_nav_links = $myGallery->back_forward_link();
$total_recs = $myGallery->get_total_rows();

$p=0;
while($p<$myGallery->rows_on_page)
{
$row = mysql_fetch_row($result);
$p++;
//Display my item
}

However, while it does go through the while loop 6 times, it does not retrieve 6 items. It only retrieves 4. But changing the below line will affect the number of pagination links displayed (the forward and back links).

$myGallery->rows_on_page=6;

So, how can I get my page to display all 6 of the items I want it to display? I have the pagination links displaying properly.

TIA.

Comments / discussions

Olaf posted on 2008-04-22 10:03:39 #

Hi,

try
$myGallery = new MyPagina(4);

telconstar99 posted on 2008-04-23 02:21:20 #

I tried the following, it seemed to have no effect:

$myGallery = new MyPagina(4);

or

$myGallery = new MyPagina(6);

Olaf posted on 2008-04-23 05:43:52 #

sorry, that was the total limit of records for your result.

check the config file for:

define("NUM_ROWS", 5); // the number of records on each page

telconstar99 posted on 2008-04-24 06:13:26 #

Yup, that works.

However, that fixes all my instances of the pagination class to that number. So I played around with it some more and apparently I had all the correct code in there but I you have to have this statement pretty early:

$myGallery->rows_on_page=10;

So once you have that in pretty early it seems to work. Thanks for your help.

Olaf posted on 2008-04-24 06:41:11 #

yes right, if you use that class for multiple instances, this constant variable is not very useful. Your solution is the best you can do...