Jump to content

Temp table is deleted -- Do I need to use cookies?


mrherman

Recommended Posts

I'm a PHP novice.

 

When an html table page is opened on a new, a temporary table is created.  When the user selects records from the table, they are inserted into the temporary table.

 

But if the user decides to select more records on the current page, or go to the next page to select records, the temporary table is RE-CREATED and records are, of course, lost.

 

What is the concept for making sure that as long as the user is logged in, the temporary table is created only once?  Do I need to use cookies (which I haven't done before).

 

Thanks!

Thanks for your reply!

 

This is not a live site yet.  Here is what I'm trying to do:

 

1. Several pages of records are shown to the user, 20 records to a page.

2. User selects records from page 1 (using checkboxes).  The records are inserted into the temporary table which has been created when the user selects the first set of records.

3. The user selects records from other pages (as the user chooses).  After each page of selections, the records are added to the same temp table.

4. When the user has completed selecting all relevant records, the records from the temp table are added to a "permanent" table, and the temp table is deleted.

 

Interestingly, I tried to do something with SESSIONS.  When the user gets to the first page of records, this is the code:

 

session_start () ;
$_SESSION [ 'tempdb' ] = "false" ;

 

Then when the temp table is created, this is the code:

 

if ( $_SESSION [ 'tempdb' ] = "false" )
   {
      include_once "db_login.php" ;
      
      $sql = "DROP TEMPORARY TABLE IF EXISTS temp_sap_id_select" ;
      mysql_query ( $sql ) or ( "Error " . mysql_error () ) ;
      
      $sql = " CREATE TEMPORARY TABLE temp_sap_id_select 
                     (
                       `current_page` INT NOT NULL,
                       `total_pages` INT NOT NULL,
                       `select_date` DATE NOT NULL,
                       `select_schcode` CHAR(6) NOT NULL,
                       `select_user` CHAR(30) NOT NULL,
                       `select_id` CHAR(9) NOT NULL
                     ) " ;
      mysql_query ( $sql ) or ( "Error " . mysql_error () ) ;
      $_SESSION [ 'tempdb' ] = "true" ;
   }

 

However, this doesn't work, because (I guess) the SESSION variable is reset to "false" every time the user updates the temp table with records.

 

The biggest problem using Temp MySQL tables in a PHP script, is the tables are destroyed when the script completes, as the mysql connection automatically closes.  Thus the MySQL session expires.

 

Thanks, PFMaBiSmAd and jcbones.  This is very helpful.  So, does the script complete when the PHP/HTML page has run its course, or does the script continue until the user logs out after further transactions?  Oh, wait, wait...I get your point...Right, this is why a db login must be done each time, isn't it?

 

OK, I think I get it.  Obviously, this wasn't clear to me before.  So temp tables are out, and a permanent table will have to be used.

 

Thanks very much!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.