I decided that I would like to track the searches that users are making on my site, so I created a MySQL table called 'Searches' with a few simple fields, and a model (class) to facilitate the insertion and management of the saved searches.
The model function that saves the search is:
public function create() {
$q = $this->db->query("INSERT INTO
`searches` (
`section`,
`keywords`,
`results`,
`location`,
`date`
) VALUES (
%s,
%s,
%s,
%s,
%s
)",
$this->section,
$this->keywords,
$this->results,
$this->location,
date('Y-m-d G:i:s'));
$this->id = $this->db->last_insert($q);
}
...and in my controller, when the page is loaded I go:
/* lets save the search if there is one */
if(isset($_GET['q'])) {
$search = $this->load->model('Searches_Single',null);
$search->set('section','sale');
$search->set('keywords',$_GET['q']);
$search->set('results',$grand_total);
$search->set('location',$this->location->id);
$search->create();
unset($search);
}
What is baffling me is that 1-4 duplicate rows are often being inserted instead of the just 1 that I expect.
There are no loops, no redirecting...just a very simple pageload. Frankly, I believe this happened to me the last time I attempted this.
UPDATE
This does not happen in my local development environment...only in production (scary). Both share the exact same code...could this be a server thing?
UPDATE NUMBER 2 I am finding that this seems to be happening on page opening and closing. AKA - I check the time the page opens, and the script logs a search then...and then I check the time the page finishes loading, and the script seems to be logging a search there as well...
GAHHH