Mysql Query Retrieving Posts And Filtering Based On Specific Date Intervals
Solution 1:
The answer is: it depends on the use case. You have to be aware of the trade-offs you're making:
Implementing it in JavaScript means that you will retrieve the entire MySQL table in one go, and perform filtering in the browser.
Query execution speed will be fast since no conditions need to be evaluated by the database
You will only need one round-trip to the database
The amount of data that needs to be sent over the wire will potentially be large
The amount of data that needs to be held in memory by the browser will potentially be large, so data transfer will be slower
Execution in the browser will potentially be slow if a large volume of data needs to be filtered
Implementing it in a MySQL query means that you will retrieve only that part of the table that matches your conditions and will not have to perform filtering in the browser.
Query execution speed will be slower since the database has to evaluate the conditions
You will potentially need multiple round-trips to the database
The amount of data that needs to be sent over the wire will be smaller, so data transfer will be faster
The amount of data that needs to be held in memory by the browser will be smaller
Execution in the browser will be fast since no filtering logic needs to be applied
As you can tell from the listings above, the size of the table plays a crucial factor. If the table is small, I would opt for the JavaScript approach. If the table is large (or will potentially grow large), I would opt for the query approach.
Solution 2:
Yes um handle by ajax...
<selectid="select"><optionvalue="all">All Time</option><optionvalue="day">Past Day</option><optionvalue="weel">Past Week</option><optionvalue="month">Past Month</option><optionvalue="year">Past Year</option></select><script>
$(document).ready(function(){
$("#select").change(function() {
$.ajax({
type: 'post',
url: "getSql",
data: { $(this).val() },
success: function($response) {
response = $.parseJSON(reponse);
$.each(response, function(k, v) {
// key and value
$("YOUDIV").append(VALUE)
});
}
});
})
})
</script>
Post a Comment for "Mysql Query Retrieving Posts And Filtering Based On Specific Date Intervals"