Speed up query code
Posted: Fri Feb 01, 2008 7:00 am
~pickle | Please use [ php ] tags when posting PHP code. Your post has been updated.
Hi,
how could I speed up the following code:
The result's code is an array ($ahits) of how many hits there is in each hour of the day.
Could I exclude the for cycle and use only a mysql query to retrieve that array?
Thank you
~pickle | Please use [ php ] tags when posting PHP code. Your post has been updated.
Hi,
how could I speed up the following code:
Code: Select all
for ($i=0;$i<=23;$i++) {
$hour_fromdate = strtotime("+ ".$i." ".$strto, $this->from_date);
$hour_todate = strtotime("+ 1 ".$strto, $hour_fromdate);
$ghits = $wpdb->get_var("SELECT COUNT(*) FROM (SELECT DISTINCT column FROM $tableName WHERE column IS NOT NULL AND timestamp BETWEEN $hour_fromdate AND $hour_todate) AS itemstot");
$ahits[ ] = $ghits;
}
Could I exclude the for cycle and use only a mysql query to retrieve that array?
Thank you
~pickle | Please use [ php ] tags when posting PHP code. Your post has been updated.