pagination php

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
rwahdan
Joomla! Apprentice
Joomla! Apprentice
Posts: 33
Joined: Thu Jul 05, 2018 8:12 am

pagination php

Post by rwahdan » Thu Jul 26, 2018 6:15 am

Hi,

I have the below code that will calculate number of records in the table inside my DB. What i need to do now is to show 5 records each time and have number under that to show next records like 1 2 3 ...

Code: Select all


<?php
// You can place PHP like this

	$db = JFactory::getDBO(); 
	$query = "SELECT SQL_CALC_FOUND_ROWS * FROM tbl_userlogs";
	$db->setQuery( $query );
	$rows = $db->loadObjectList(); 

	$db->setQuery('SELECT FOUND_ROWS();');
	$count = $db->loadResult() ;

	echo $count;

?>

Thanks

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2897
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: pagination php

Post by SharkyKZ » Thu Jul 26, 2018 6:54 am

Create a component. Stick with Joomla's MVC which already does what you need. See this guide https://docs.joomla.org/J3.x:Developing ... _Component

You can use a tool like https://ibrini.com/en/ or https://www.component-creator.com/en/ to easily create basic components.

rwahdan
Joomla! Apprentice
Joomla! Apprentice
Posts: 33
Joined: Thu Jul 05, 2018 8:12 am

Re: pagination php

Post by rwahdan » Thu Jul 26, 2018 7:01 am

Thanks,
there is no way to do through php coding? I don't know how to create components, I just need to include this in a module.

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2897
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: pagination php

Post by SharkyKZ » Thu Jul 26, 2018 7:56 am

There is, that's the point. You can write as much custom code as you want. But Joomla already contains code to create paginated views in components. If it needs pagination, it should probably be a component, not a module.

If you really need a module, you can try this:

Code: Select all

use Joomla\CMS\Pagination\Pagination;
$pagination = new Pagination($total, $start, $limit);
echo $pagination->getListFooter();
But this will cause issues because the links will point to different pages inside current component (you can't link to a module).

rwahdan
Joomla! Apprentice
Joomla! Apprentice
Posts: 33
Joined: Thu Jul 05, 2018 8:12 am

Re: pagination php

Post by rwahdan » Thu Jul 26, 2018 8:28 am

SharkyKZ wrote:
Thu Jul 26, 2018 7:56 am
There is, that's the point. You can write as much custom code as you want. But Joomla already contains code to create paginated views in components. If it needs pagination, it should probably be a component, not a module.

If you really need a module, you can try this:

Code: Select all

use Joomla\CMS\Pagination\Pagination;
$pagination = new Pagination($total, $start, $limit);
echo $pagination->getListFooter();
But this will cause issues because the links will point to different pages inside current component (you can't link to a module).
Thanks for the answer, now i guess i will have to make a component then...can you guide me what i will need to do to achieve my goal (tips not codes)?

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30888
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: pagination php

Post by Per Yngve Berg » Thu Jul 26, 2018 4:09 pm



Locked

Return to “Joomla! 3.x Coding”