I would like to create buttons that change sorting of database output.
Im quering one table and output results with some pagination class. I can easily ORDER results by columns ascending or descending.
$sql = "SELECT id, name, address FROM restaurant WHERE accepted = '1' ORDER BY id DESC";
$pagination = new Pagination();
$pagination->page = $_GET['page'];
$pagination->perPage = 10;
$pagination->classNormal = 'someClass';
$pagination->classSelected = 'someClass2';
$pagination->sql($sql);
Then in while loop I have those results and another mysql auery.
while($row = $pagination->getRows()) {
$sql2 = "SELECT COUNT(DISTINCT prod_name) AS nr_of_prod FROM menu WHERE id = '".$row['id']."'" ;
$do1->doQuery($sql2);
$row_amount = $do1->getRows();
//... and here is some data output
Now, the question is how can I sort/order all the paging result by column from this second query (for exampple by nr_of_prod)?
Put the second query right in the first:
Also, why are you using some pagination class instead of using MySQL
LIMIT?You can also write it like this (profile both and pick, the best one depends on the relative size of the tables):