[eluser]mindSmile[/eluser]
****Update: This question may have been simplified by my latest post,****
In an application I'm developing, there are pages where, when the user visits them, some information is processed and stored in the database with their userinfo.
One of the items to be updated is "last_book", where the id of a book being viewed on a page is stored each time any book is view, clearing out the last stored bookID. Sounds pretty typical, right?
Wrong! In firefox and opera, it just isn't updating [Edit: except when I log the variable using firephp, which makes things magically work]. In chrome and safari it works perfectly. In FF and Opera, I'll access the page, check the table in phpMyAdmin, and it just remains blank, every time except when the book id is 12, or i'm logging the variable with firephp. In those specific cases it'll update fine, but if I visit another book (not book 12) or comment out all of the firephp logging, it becomes blank again. I've tried echoing every variable along the way, and it looks like it *should* work. Also, I'm not entirely sure what type of field I should have for this piece of information in the database, as it's just going to be a number.
Books are stored in a table called "books", and members are stored in a table called "members". Both have a primary index auto-incrementing 'id' field.
Both the Books_model and Members_model are autoloaded.
Enough of my yapping, here's my code (trying not to bug you with unrelated parts):
Members_model
Code:
<?php
class Members_model extends Model{
/****************************/
/* Account Functions */
/****************************/
function update_member($bookID, $langCode){
$id = $bookID;
$userdata = $this->get_user_data();
$email = $this->session->userdata('email');
$bookString = $userdata['books_accessed'];
$langString = $userdata['langs_accessed'];
$lastBook = $bookID; //This is the piece for the last book
$accessedBook = $this->add_to_books_accessed($bookString, $id);
$accessedLang = $this->add_to_langs_accessed($langString, $langCode);
$data = array(
'langs_accessed' => $accessedLang,
'books_accessed' => $accessedBook,
'last_book' => $lastBook
);
$this->db->where('email',$email);
$this->db->update('members',$data);
}
function get_user_data(){
$useremail = $this->session->userdata('email');
$this->db->select('id,email,langs_accessed,books_accessed,shelf,last_book,last_spot');
$this->db->where('email',$useremail);
$query = $this->db->get('members');
$row = $query->row();
$userdata = array(
'id' => $row->id,
'lang_nat' => $row->lang_nat,
'langs_accessed' => $row->langs_accessed,
'books_accessed' => $row->books_accessed,
'shelf' => $row->shelf,
'last_spot' => $row->last_spot
);
$query->free_result();
return $userdata;
}
function add_to_langs_accessed($langString, $lang){
if(isset($langString) && $langString != ''){
$cleaned = $this->clean_imploded_string($langString);
$result = $cleaned['exploded'];
$in_langs = array_keys($result,$lang);
$matches = count($in_langs);
if($matches != 0){
$addLang = $cleaned['imploded'];
} else {
$addLang = $cleaned['imploded'] .'~'. $lang;
}
} else {
$addLang = $lang;
}
return $addLang;
}
function add_to_books_accessed($bookString, $id){
if(isset($bookString) && $bookString != ''){
$cleaned = $this->clean_imploded_string($bookString);
$result = $cleaned['exploded'];
$in_books = array_keys($result,$id);
$matches = count($in_books);
if($matches != 0){
$addbook = $cleaned['imploded'];
} else {
$addbook = $cleaned['imploded'] .'~'. $id;
}
} else {
$addbook = $id;
return $addbook;
}
}