Forums

(solved) pagination

chrissy6930 02 Jun, 2011
hi all,

I am trying to add pagination to my forms using J! defaults

in the html of form listresults I've added:
<?php
// prepare pagination
global $mainframe;
$database = JFactory::getDBO();
$user = JFactory::getUser();
$limit = $mainframe->getCfg('list_limit');
$limitstart = JRequest::getInt('limitstart', 1);
$limitstart = ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );
$database->setQuery("SELECT COUNT(*) AS total FROM #__chronoforms_data_results WHERE `cf_user_id` = '".$user->id."' ");
$total = $database->loadResult();
jimport('joomla.html.pagination');
$pageNav = new JPagination($total, $limitstart, $limit);
?>

    <form action="<?php echo JRoute::_('index.php?option=com_chronoforms&Itemid='.$Itemid); ?>" method="post" name="form">
      <p>
      <?php if($limit < $total) echo $pageNav->getListFooter(); ?>
      </p>
    </form>


$total is currently 6. with List Length in global config set to 5 the list-footer would properly display with the limit box set to 5 and 2 pages indicated as available.

for getting the pagination appliad to the list of rows I adjusted in ../administrator/components/com_chronoforms/admin.chronoforms.php in function show_data
if(isset($_POST['cb']) && !empty($_POST['cb'])){
$database->setQuery("SELECT * FROM ".$table_name." WHERE ".$primary."='".$_POST['cb'][0]."'
								ORDER BY `date` DESC, `group_select`");

for:
// prepare pagination
$user =& JFactory::getUser();
$limit = $mainframe->getCfg('list_limit');
$limitstart =& JRequest::getInt('limitstart', 1);
$limitstart = ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );
$database->setQuery("SELECT COUNT(*) AS total FROM #__chronoforms_data_results WHERE `cf_user_id` = '".$user->id."' ");
$total = $database->loadResult();
jimport('joomla.html.pagination');
$pageNav = new JPagination($total, $limitstart, $limit);
//show data
if(isset($_POST['cb']) && !empty($_POST['cb'])){
$database->setQuery("SELECT * FROM ".$table_name." WHERE ".$primary."='".$_POST['cb'][0]."'
								ORDER BY `date` DESC, `group_select`
								LIMIT $pageNav->limitstart,$pageNav->limit");

Similar to the change in the order by mentioned in this thread
http://chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=2&t=21986
the applied changes are not working. what am I doing wrong ? 😶
GreyHead 02 Jun, 2011
Hi chrissy6930,

Good luck but I'm afraid that you are on your own hacking the ChronoForms code. I just don't have time to help with this at the moment.

Bob
Max_admin 03 Jun, 2011
Hi chrissy6930,

What are you trying to do exactly ? the Chronoforms admin already has pagination, I can't understand why do you need to hack the core.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
vales 03 Jun, 2011
I think he's trying to do the pagination in frontend of the form with Action DB Multi Record Loader.
It is very important.
chrissy6930 04 Jun, 2011
Hi Max and vales,

I am trying to add pagination to the form(s) where I'm listing records.
therefore I reverted ../administrator/components/com_chronoforms/admin.chronoforms.php back to default
and instead tried adding the pagination logic to the db multi record loader action.

only its still not working

please find attached the modified action (GH are my initials...)

ps: @vales: I am a woman by the way🙂
vales 04 Jun, 2011
I have implemented some php script in a form with the action Record DB Multi Loader to get the pagination of the form.

The main problem was understood to be disabled the form tags and put them manually in the appropriate places.

I attach the backup of the form and the test table.

This demo works without change to the file administrator \ components \ com_chronoforms \ form_actions \ db_multi_record_loader \ db_multi_record_loader.php. But for proper operation should be recovered total records found.

These modified lines in the file db_multi_record_loader.php allow you to get the result.

			//run the sql and get the data
			global $total; //new
			$sql1 = "SELECT count(*) FROM `".$params->get('table_name', '')."` AS `".$model_id."`".$assoc.$where; //new
			$database->setQuery($sql1); //new
			$total=$database->LoadResult(); //new
			$sql = "SELECT ".implode(", ", $fields)." FROM `".$params->get('table_name', '')."` AS `".$model_id."`".$assoc.$where;
			$database->setQuery($sql);
			$data = $database->loadAssocList();
			//process the data if association was enabled


In this case then the script must be modified in the Custom code - footer

</table>
<?php 
global $total; // modify db_multi_record_loader.php
global $limit;
//echo $limit."-<br />";
echo "<br />";
//$total=21;
$limitstart=Jrequest::getVar('limitstart','0','get');
jimport('joomla.html.pagination');
$pageNav = new JPagination($total, $limitstart, $limit); 
echo $pageNav->getListFooter(  );
?>


It remains to complete the CSS code to show the pagination correctly.

ps: @vales: I am a woman by the way🙂



Now I understood. Good job chrissy6930.
chrissy6930 07 Jun, 2011
hugh thankies vales! I got it to work! 😀
vales 07 Jun, 2011
In joomla 1.6 for the horizontal alignment insert action Load CSS with this code

ul li {
display: inline;
}


Now all OK.
itchibahn 10 Aug, 2011
I've downloaded 16v419.zip and seems to work except two prblems.

1) when you change the Display# pulldown, it displays blank page. I've tested it on Joomla 1.5.23 with Chronoforms 4.0 RC 1.9.

2) it shows two pages even when there's less than five on page. and when you click on page 2 or next, it show no records available.

Any ideas?
Max_admin 17 Aug, 2011
Hi,

@vales, thank you for sharing it!🙂

This feature has been added to the new version V4RC2.0, you may test it when its out and let me know if it works well for you or not, you may also contact me through the "COntact us" page to get it early.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger