public function StatsPro::store_day in Statistics Pro 6.2
Same name and namespace in other branches
- 6 statspro.inc \statspro::store_day()
Save day information to database.
Parameters
string $date:
array $values:
File
- ./
statspro.inc, line 879 - statspro class for Statistics Pro module.
Class
- StatsPro
- Manages the data saving and retrieval according to the user defined parameters.
Code
public function store_day($date, $values) {
$found = db_result(db_query("SELECT COUNT(*)\n FROM {statspro}\n WHERE day = '%s'", $date));
// update row
if ($found) {
$sql_fields = array();
$sql_values = array();
foreach ($this->fields as $field => $desc) {
$sql_fields[] = $field . ' = ' . $field . ' + %d';
$sql_values[] = isset($values[$field]) ? (int) $values[$field] : 0;
}
// add date to argument array
$sql_values[] = $date;
db_query("UPDATE {statspro} SET\n " . implode(', ', $sql_fields) . "\n WHERE day = '%s'", $sql_values);
}
else {
$sql_fields = array();
$sql_values = array(
$date,
);
$sql_vars = array();
foreach ($this->fields as $field => $desc) {
$sql_fields[] = $field;
$sql_values[] = isset($values[$field]) ? (int) $values[$field] : 0;
$sql_vars[] = '%d';
}
db_query("INSERT INTO {statspro}\n (day, " . implode(',', $sql_fields) . ")\n VALUES('%s', " . implode(', ', $sql_vars) . ")", $sql_values);
}
}