473,809 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Relational Database Question

Hello,

I'm pretty new to setting up databases, but so far I'm getting along
swimmingly. But I have one question. I'm setting up a database for a
client who wants to sell tickets to their theater online. There are a
LOT of different parameters and I'd like to set it up so that when a
client selects a play and date the price is automatically generated. I
have already figured out how to get what I want, but I believe there
is a better way, I'm just ignorant to it right now. Here is the deal:

5 plays a year
5 different show times (i.e. sunday matinee, weekday evenings,
friday/sat evenings, etc.)
Each play has a different price for each show time

So I have a table (ticket_price) now that looks like this:

play ticket_type price
----------------------------------
play_1 matinee 20
play_1 week_eve 25
play_1 fri_sat_eve 28
play_2 matinee 19
play_2 week_eve 23
play_2 fri_sat_eve 25

etc....

and the order (ticket_order) table:

order_id play ticket_type meal quantity
-----------------------------------------------------------
01 play_1 matinee yes 2
02 play_2 fri_sat_eve no 5

etc...

So I match the ticket with its price for by:

mysql-> select * from ticket_order, ticket_price
where ticket_order.ti cket_type='week _eve'
and ticket_price.ti cket_type='week _eve'
and ticket_order.pl ay='play_1'
and ticket_price.pl ay='play_1';

and from there I can use PHP to create a shopping cart type of thing.
But the ticket price table seems redundant to me. But for the life of
me I cannot think of how to fix it up. Or, perhaps, the above SELECT
is more complicated than it needs to be. I've poured over my books and
did searches, but nothing seems to touch on this particular subject. I
have a horrible feeling i'm missing something elementary!

Thanks!
Shane
Jul 20 '05 #1
4 1380
Shane wrote:

5 plays a year
5 different show times (i.e. sunday matinee, weekday evenings,
friday/sat evenings, etc.)
Each play has a different price for each show time But the ticket price table seems redundant to me. But for the life of
me I cannot think of how to fix it up. Or, perhaps, the above SELECT
is more complicated than it needs to be.


The ticket_price table is not redundant, if the ticket price varies per
play and per show. It's okay to generate a few rows -- it sounds like
you're going to have only 25 new rows per year. This isn't an
excessively costly proposition.

You're making it a bit complicated in part because you have two columns
that identify a play, where you could have one. There's no exact right
way to do it, but here's how I would propose to design it:

create table ticket_price (
ticket_id integer not null auto_increment primary key,
play_title varchar(100) not null,
show_datetime datetime not null,
ticket_price numeric(5,2),
offers_meal tinyint not null default 0,
on_sale tinyint not null default 1
);

Create a separate record for ticket_price for each showing. Not only
for each of the five showings during the week, but for every showing for
that play for the entire season. This way, you can print the date &
time on each customer's ticket, you can track when a given showing has
sold out so you can stop selling tickets, and you can make reports at
the end of the season to find out which dates & times were most popular,
which might help plan for next season.

I've also added a proposed column "offers_mea l" because some shows like
matinees may not have an option to buy a meal.

The ticket price might be redundant in typical cases, because it's often
going to be one price for a matinee vs. evening, or one day of week vs.
another day of week. But tracking it in this table enables you to vary
it based on date (maybe later in the run of the play, you would want to
reduce prices to keep filling the seats), and also avoids creating yet
another table, assuming you go with the one-record-per-datetime design I
describe above.

Now the ticker_order table:

create table ticket_order (
order_id integer not null primary key,
ticket_id integer not null references ticket_price,
quantity_seats integer not null default 1,
quantity_meals integer not null default 0
);

Now you get the ticket price for a given order with this simple query:

select p.ticket_price * o.quantity_seat s
+ (MEAL_PRICE * o.quantity_meal s) as order_total
from ticket_price p inner join ticket_order o
on p.ticket_id = o.ticket_id;

Just my suggestions. There are doubtless many ways to design this
solution. The complexity of tables and "redundancy " of data depends on
how many figures can vary independently of one another. There's also a
tradeoff between redundancy and complexity of the data model; sometimes
it's simpler to create a redundant data design (also known as a
non-normalized data model) than to break it down perfectly into tables
and sub-tables, and deal with the programming that would be required by
this.

Regards,
Bill K.
Jul 20 '05 #2
Thank you Bill for your enlightening description. That helps a lot.
Now, though, I'm wondering about populating the tables. I'd like to
set it up so that when we add plays, we can give the run time (ie.
from Feb. 2, 2004 to April 10, 2004) and have the database
automatically filled with a PHP script that will figure out the days,
prices and such. I wonder if there is anything else to take into
consideration with the database when anticipating this feature.

Thank you for your help.

Shane
Jul 20 '05 #3
Shane wrote:
Thank you Bill for your enlightening description. That helps a lot.
Now, though, I'm wondering about populating the tables. I'd like to
set it up so that when we add plays, we can give the run time (ie.
from Feb. 2, 2004 to April 10, 2004) and have the database
automatically filled with a PHP script that will figure out the days,
prices and such. I wonder if there is anything else to take into
consideration with the database when anticipating this feature.


Hmm. If the times are pretty uniform, for instance if matinees are
always at 2pm and do not include meals, you could create another table
that has some of the common show times, with any other relevant
attributes like that. For example:

create table show_times (
show_time_id integer not null primary key,
day_of_week enum(0,1,2,3,4, 5,6) not null, # Sunday = 0
time_of_day time not null,
ticket_price numeric(5,2),
offers_meal tinyint not null default 0
);

Then use this to create a pick-list in your user interface, so the
person entering data for a new play can select which days & times the
play will be shown. Then based on the show times selected, your code
can generate the full list of showings between the play opening and closing.

Basically this is just a way to move some hard-coded values out of the
PHP code and into the database. That's often a good thing to do,
because it makes it easier to add more choices later.

Regards,
Bill K.
Jul 20 '05 #4
Bill Karwin <bi**@karwin.co m> wrote in message news:<cb******* **@enews3.newsg uy.com>...
create table show_times (
show_time_id integer not null primary key,
day_of_week enum(0,1,2,3,4, 5,6) not null, # Sunday = 0
time_of_day time not null,
ticket_price numeric(5,2),
offers_meal tinyint not null default 0
);
ERROR 1064: You have an error in your SQL syntax.

http://dev.mysql.com/doc/mysql/en/ENUM.html
"An ENUM is a string object.."


Ok, we try this instead (column names shortened to avoid line wrap):

mysql> create table show_times (
-> show_time_id integer not null primary key,
-> day_wk enum('0','1','2 ','3','4','5',' 6') not null,
-> tm_of_dy time not null,
-> tck_prc numeric(5,2),
-> off_ml tinyint not null default 0
-> );
Query OK, 0 rows affected (0.00 sec)

mysql> insert into show_times values (3.14, -1, 'never enough time..',
'way too expensive!!', 128);
Query OK, 1 row affected (0.00 sec)

mysql> select * from show_times where day_wk=0;
+--------------+--------+----------+---------+--------+
| show_time_id | day_wk | tm_of_dy | tck_prc | off_ml |
+--------------+--------+----------+---------+--------+
| 3 | | 00:00:00 | 0.00 | 127 |
+--------------+--------+----------+---------+--------+
1 row in set (0.00 sec)

mysql> select version();
+------------+
| version() |
+------------+
| 4.0.14-Max |
+------------+
1 row in set (0.00 sec)

Note:

* Select on an enum column with a numeric value returns rows matching
the corresponding index, not data.
* 3.14 is accepted as an integer and rounded to 3.
* -1 is not the set of valid enums. The default empty string is
inserted instead .
* Illegal time values are converted to '00:00:00'.
* Illegal numeric values are converted to zero.
* Out-of-bounds numeric values are clipped down to the appropriate
endpoint of the range.

MySQL behaves as documented, but probably not as expected.

Lesson learnt: *NEVER* trust MySQL to enforce data integrity unless
you are absolutely sure it performs as you expect.
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
7120
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. Yensao
5
3227
by: Markus Seibold | last post by:
Dear NG, I am working on a student project about a mobile tourism information system and among others I have to answer the question whether to use: - a relational database - a XML-native database - a hybrid (XML atop relational database) Can anyone please provide me with links and preferably article on this topic (so that I can cite them in my paper)?
0
2410
by: Mike | last post by:
Hello, I'm trying to understand how to map hierarchical XML data to relational database tables, but I seem to be missing something. I'm not a database expert, but I know the basics. XML seems so much more intuitive to me, though. Anyway, let me make up an example: Say we have an address book, in XML format, that is to be uploaded by a customer and then mapped into relational database tables. I would start by creating an XML Schema...
0
2309
by: Stylus Studio | last post by:
DataDirect XQuery(TM) is the First Embeddable Component for XQuery That is Modeled after the XQuery API for Java(TM) (XQJ) BEDFORD, Mass.--Sept. 20, 2005--DataDirect Technologies (http://www.datadirect.com), the software industry leader in standards-based components for connecting applications to data and an operating unit of Progress Software Corporation, today announced the release of DataDirect XQuery(TM), the first embeddable...
49
3365
by: Mike MacSween | last post by:
I frequently hear that there isn't a commercially available dbms that fully implements the relational model. Why not? And which product comes closest. Mike MacSween
3
2029
by: cassandra.flowers | last post by:
I'm designing a database because I have to do it for the preperation work for my A-Level ICT exam. The database is for a building company. It has to store information on building projects (tblProject) and employees (tblPersonnel) then link them together.
3
6208
by: Robert Abi Saab | last post by:
Hi everyone. I just finished a course on PostgreSQL and I found out that PostgreSQL doesn't provide any object relational features (as claimed in the official documentation), except table inheritance and very limited user defined types (I defined a UDT with 2 attributes and couldn't use it in a table, and the trainer said it must contain 1 attribute at most so that it can be used (as a column) in tables) So my question is whether...
6
1655
by: Shwetabh | last post by:
Hi, I have a very simple question. In what cases are relational databases necessary? Are they really necessary in cases where only a single type of query is to be performed based on one unique field or can we just put all fields together in a single database and just access them through that unique field?
5
1381
by: sh | last post by:
I am working on a database project, and I'm trying to think "objectively". Are there any tools that will map my "objects" to relational tables? I'd prefer a freebie, or something faily low-cost to start off. Thanks for any assistance.
7
1666
by: Pradeep | last post by:
Hello, I need to take a set of input tables and create an XML output file. The format of the XML output must be user-definable and must be intuitive enough for non-techies to use. input table(s) + SomeSchemaDefinition ==XML file I have seen examples of XML file generation with fixed scope. For example, if input table (called customer) is as follows:
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.