How to Drop Table on Session Condition

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
banko
Forum Newbie
Posts: 3
Joined: Mon Apr 17, 2006 8:17 am

How to Drop Table on Session Condition

Post by banko »

Hi Everyone,

I have created a php/mysql site. When a guest comes to the site a temp table is automatically created for them in mysql, saving all their entries and data. I would like to have this temp table dropped when the guest leaves the site. Can someone please tell me how to accomplish this?



Thanks for your help guys,

Banko
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why not keep all this data about their entries in a single table?

I'd suggest using database sessions or a similar facility.
banko
Forum Newbie
Posts: 3
Joined: Mon Apr 17, 2006 8:17 am

Post by banko »

all the data for that user is stored in a single table, i want to know how to drop that table when they leave.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

And I'm suggesting that you store that information, across all sessions, in a single table. No more temporary tables.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

This sounds like a bad design. I wouldn't be creating new tables on a per-user basis. Rather I would make use a the idea of relational databases and have tables for the relevant components. So you'd have for example a users tables, and a user_preferences table.
banko
Forum Newbie
Posts: 3
Joined: Mon Apr 17, 2006 8:17 am

Post by banko »

the table is for a temporary quote.

Basically the person fills out a form, the data is retrieved from the form, a query is sent to the database to get the rates on the selected item. Calculations are made to the data submitted and then all is saved to the guests table so he can keep adding items. Every time he makes an addition the page displays what he has added so far and what the total is, and gives the option to add or remove data from his table.

Basically unless you know away to store and keep a running track of his entries without creating a table for him I would love to here it.

I am new to database design, and welcome any suggestions. Think of the table as a shopping cart that i want deleted at the end of his session.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

two options:
Two tables or one table

The two table approach
Store minor (more global) details about the possible order here (this is where the session data is sent, overall)

The second table holds items in their order. Each item is keyed to the Session ID or some other reference to their entry in the first table.


The one table approach
Only items are kept in this table. They reference to the user in some unique way. Some of the data stored here will likely be redundant.
Post Reply