I've spent far too long trying to come up with a good solution to this problem on my own. Haven't found any good answers to help, though I've tried meshing solutions from different answers without luck.
Goal: Present a paginated Projects page containing data from multiple tables.
I'm using several joins in a single MYSQL query, because I wanted to avoid running queries in a PHP loop. That alone has introduced a fetch_assoc problem, where I had to build my own results array from the while(fetch_assoc)
loop because of the repetitive rows resulting from the query. However, the next problem is that the query runs through a pagination class which I use to generate pagination links and get query data like num_rows and such.
So right now, I have a page showing the data I want, but the pagination class is showing me the wrong amount of rows and pagination links. Not sure what the best way is around this problem. Hoping to get some ideas from one of you brilliant experts!
Code is basically:
$sql = "...."
$projects = new pager($sql)
echo $projects->num_rows
while($projects->fetch_assoc){
build new array from data
$project_array[][][]
}
foreach($project_array){
display data from all tables...
}
$projects->showPageLinks
This SQLFiddle provides an example of the data I get:
Notice that there are 7 result rows, but for only 4 projects. So the pagination class shows 7 num_rows (rightfully) but there's only 4 projects.
Any ideas welcome!
I though of maybe concatenating sub query results from other tables into string value in own columns and parsing that with php explode()
and such, which would then produce single project rows with all the data, but I haven't been able to accomplish that yet.
Thank you in advance for your help!