I would prefer to return simple data and manipulate it with PHP. In any case, you will undoubtedly iterate over the results, so why not just drop the tags in both directions in the interval of time?
This, however, is not my main argument - if you end up using the same data for multiple instances, you can cache and reuse the results by embedding the returned data in different templates in accordance with the usage requirements (not possible if the returned the data set has a viewing specific code for each row).
In addition, the request should be separated from the code that creates the view in any case, so when updating the final markup it will be easier to modify PHP, which creates the markup (in the same file as the other markup), than searching for a request to change the markup. echo '<th>'.$field.'</th>'; also much clearer than his intentions, not just echo $field; .
In the end, it depends on personal preferences, but, as in good practice for MVC structures and usually clean and maintained code, I will definitely vote for the markup that needs to be done in PHP
TL DR
- Use PHP - you might still get stuck with it anyway
echo '<th>'.$field.'</th>'; has clearer intentions (more readable) than echo $field;- If the data should be used elsewhere, you can cache one request for reuse with another markup template, instead of having to make multiple requests each time by adding different wrapped tags
- Databases are best left to search for data for readability (hence MVC relocation), then this data can be processed in a language more suitable for the job, such as PHP
source share