4
Suppose, in a query to the MYSQL database, I need to take the last 1000 dice released, however, within these displayed results, his order must be growing (and not decreasing, as would happen in the ORDER BY ID DESC Limit 1000
).
The response to such data shall be via JSON, through function json_encode
of PHP, at a specific url, where who will capture and process this data is the Javascript.
The question I have is this: Considering examples 1, 2 and 3 and considering that the data should be formatted in reverse order, which of these would be the most appropriate way, taking into account the memory consumption and data processing speed ?
1 - MYSQL
SELECT * FROM (
SELECT id, pessoa_id, chat
FROM chat
ORDER BY id DESC LIMIT 1000
) AS reverse_chat ORDER BY id ASC
2 - PHP
return Response::json(array_reverse($chat)); //lembrando que é $chat é um array com 1000 dados
3 - Javascript
$.ajax({
url: 'ajax_response',
dataType: 'json',
data: {pessoa_id: pessoa_id},
success: function(response){
// response também possui 1000 dados
var html = _.template(tpl_chat, {chat: response.reverse()});
}
})
The option
1
is the best.– Sergio
It does not seem to me to be a constructive question in its present form. Perhaps it can be improved to make clear its real need. If you will query in the database do with SQL. If you have to do in a browser, do with JS and if you are between one and the other, do with PHP.
– Maniero
The earlier the data are processed and organized the better for the efficiency of the application. In your practical case if the data comes from a database and you can sort them when performing the query, no doubt vote on @Sergio’s comment.
– Zuul
@bigown, as mentioned in the example, I am assuming that I will use all three : Mysql in query, PHP in response, javascript in processing. I just want to know which one of these is faster and which will waste less memory.
– Wallace Maxters
Exactly, there is no real question. Therefore the question is not constructive. You want to know something that has no relevance. At least this is not clear in the question and the comment did not improve that perception.
– Maniero
@Wallacemaxters how so use all three? The question is on what is the best language to sort the information, right? and that only needs to be done once, right? then the answer is definitely option 1. Or I’m getting it wrong?
– Sergio
The title was a call for closing votes. "Better" is very much a matter of opinion. I switched to something more technical and feasible, ok?
– Oralista de Sistemas
Thank you, @Renan
– Wallace Maxters