Adding sorting and pagination to data from differe

2019-08-19 19:02发布

问题:

My task is to take data from different databases in different server and to display them in a single web page.I am working in joomla and i am able to take data from the databases using separate queries for each database.But the problem is that i need to give sorting and pagination to this web page. how can i do this without making any performance issue since all the databases contains a lot of data. Or can i use a single sql query for this ??

回答1:

To do what you're describing in Joomla I would recommend the Fabrik extension. It lets you create fairly complex front-end visualizations and table views of database data, as well as search forms and single-page table views that have nice ordering/sorting/per-column filtering controls.

More importantly, Fabrik lets you set up connections to multiple databases. Once you've set up all your database connections in Fabrik, you can then import and configure those tables in the Fabrik back-end, and after that they are all treated the same by the other parts of the administrative interface.

In other words, you can create front-end table views or search forms in the Fabrik back-end, which can do things like table joins across multiple database connections, or pre-filter result sets of a table from one database using data stored in another database (among other things) and Fabrik will take care of creating and closing the necessary database connections for you.



回答2:

You can use a GET parameter to use pass the page that you want to view, and the offset will be calculated from that.

$page = (isset($_GET['page']))? (int)$_GET['page']: 1;

$per_page = 25;

$offset = ($page-1) * $per_page; // you will have to improve this

$sql = "SELECT * FROM table 
       WHERE (condition)
       LIMIT {$offset},{$per_page}";

$result = mysql_query($sql) or die('Error : '.mysql_error());

You will have to integrate it with your code, to make it work better of course.



标签: php mysql joomla