PHP and echoing a table
PHP and echoing a table
georage
Posts: 3Questions: 1Answers: 0
I am using php to echo a table of mysql results.
My function returns every row in the database as html wrapped in a table.
How do I make my data tables only show the first 10 results and not all of them? I could make the function only return 10 results, of course, but I want to retain the functionality of the data tables "next" button.
thanks for any assistance.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Each row is an individual table? Could you link to the page showing the issue (per the forum rules) please? I'd need to see the HTML that is being generated.
Allan
Thanks for the reply. The page currently does not show anything because I am retooling the php function to return an array of values instead of echoing the entire table.
But, i generally use a php function to echo any html i need for dynamic divs. here is the php function i was using to create the table and echo it back to jquery in an ajax call.
after the table is initialized ... $('#overlayTable').DataTable(); ... the table generated by the following function looks fine, but has every row in the database (hundreds of rows) and not just 10 as indicated by the Data Tables dropbox. Sorting does not work either.
It would be great if I could make my tables on the server side, since that is how I usually do such things, but I am willing to learn a new method.
thanks again for your time. it seems like the method I am trying to use would be very common, but maybe not.
```
require_once("functions.php");
function getCrew(){
$mysqli = connectToDB();
$html = $html . '</table>';
echo $html;
}
mysqli_close($mysqli);
<?php > ``` ?>Your
tbody
element is in the loop. Move it outside the loop so there is only onetbody
element. That should address the issue.Allan
Wow! You are a genius and I am a clown!
Thanks so much for taking the time to help. It is now functioning as expected.
http://52.4.178.78/george/www/special/stars.html
If you click the "crew" button you will see the table you helped fix.
If we were on reddit I would happily award you GOLD.
Great to hear that helped :-)
Allan