Welcome Guest, Not a member yet? Register   Sign In
Why temporarily table automatically disappeared when go to a new page even using pconnect?
#1

[eluser]Unknown[/eluser]
Hi all, I am currently using CI 2.1.4 and I am going to built a shopping cart like system. I have
a few pages consist of submission forms, and after submission the clients will be redirected into a page that summarize their input and have a confirm button on it. The input data will only be inserted into the corresponding table if the client press the confirm button.

I am going to take the advantage of database calculation and so i planned to insert the data into a temporarily table on the second page and then get it back on the final page then insert the real table.

However when i am redirected to the third page i get an error that the temporarily table is not existed. It seems weird as i have set pconnect to TRUE. I use active record class for CUID , thus it matters?


#2

[eluser]micha8l[/eluser]
Hello ncoc018, from what you describe it should be working.

Can you post the concerning code so that we may better answer your question.
#3

[eluser]Unknown[/eluser]
I make it short and post the structure here:

1. the form verification controller:
function index()
{
// do some user right checking and some field verification
....
// verification landing page case
if ( $page == $landing ){
// create temp table
....
// insert data
...
// load view
}

// confirm page
if ( $page == $confirm ){
// get data from the temp table
...
// insert into the real table
...
// display result
...
}
}


2. The model affected
// function to create temporarily table
function create_temp_table()
{
// close any existing temp table
$this->dismiss_temp_table(); // close and initalise database again
$table_name = $this->db->dbprefix('temp');
$sql = <<<SQLHERE
CREATE TEMPORARY TABLE IF NOT EXISTS `$table_name` (
`request_id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
`amount` bigint(19) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`request_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
SQLHERE;
$this->db->query($sql);
return !$this->db->_error_message();
}

// add record to temp table
function set_temp($request_data=array())
{
$this->db->insert('temp', $request_data);
return $this->db->_error_message() ? FALSE : $this->db->insert_id();
}

// get temporarily record
function get_temp($request_id)
{
$this->db->select('*');
$this->db->from('temp');
$this->db->where('request_id', $request_id);
$this->db->limit(1);

$query = $this->db->get();
if ($query->num_rows() !== 0) return reset($query->result());
else return FALSE;
}




Theme © iAndrew 2016 - Forum software by © MyBB