Is it a good practice to load an entire table from a database into a class?
for example a user class? Adding all the information of users in a class?
Is it a good practice to load an entire table from a database into a class?
for example a user class? Adding all the information of users in a class?
If your table has a few data it will be fine to get all the information. e.g. if user table has only 3 users; student, tutor and admin along with their ids it is ok to get all the data.
But if the table has a large amount of data it is not a good practice to load whole table. Therefore you can use the operations such as LIMIT
to query limited number of rows.
LIMIT example:
SELECT * FROM `my_table` LIMIT 0, 5
(This will display the first 5 results from 'my_table'.)
For pagination following will be useful:
COUNT
in sql)So basically you will need to pass the pageNumber to a function (when user clicks on a page) in order to retrieve limited number of rows.