Skip to main content
9thReg
Known Participant
July 17, 2009
Question

Database setup with MySQL and PHP question

  • July 17, 2009
  • 1 reply
  • 441 views

Hello all,

I recently had a problem getting a report to work for a site I was updating.  This site is written in PHP with a MySQL database.  The application is to track customer calls to auto repair stores.  The database has a lot of foreign keys because they wanted to update information in only one spot and have multiple records be updated all at once.  So, I've got all the information from individual calls saved in the call_log table, and have foreign keys to reference information in other tables (for example this table lists what store received the call referencing the store table).  If a store changes locations, they want to have reports automatically update with the new address, connection to conversation number, etc.

In one of the responses to my question on how to get this report to work, I was told that this could be done without using foreign keys (by Normalizing the database using mapping tables).  I am still a newbie to MySQL, and after looking though a lot of manuals, tutorials, and forum posts, I am more confused now than ever.

I got the report to work using the foreign keys, but I would like to learn what I should have done with the database (and how to get the information displayed).

So for example one report would be displaying the following:

           Store                                                      Reason for the Customer Call

                                           breaks             oil change            shocks              tune up         total calls

5636 - Bloomington                  2                       4                        0                       2                   8

8875 - Duluth                           1                       6                       4                        8                  19

with links on the store name to pull up the information on that specific store.  How would I change the database (listed below) to do this without foreign keys?  Any help would be greatly appreciated.

call_log             (table that contains the following:)

call_id
conv_number
date
camp_type         (foreign key to the campaign table so it displays the campaign_id)
reason               (foreign key to the call_reason table so it displays the reason_id)
location              (foreign key to the store table so it displays the store_id)
associate
call_summary
trainig_issue      (foreign key to the training_points table so it displays the training_key_id)
visit_closed
example            (foreign key to the example_type table so it displays the example_id)


campaign          (table that contains the following:)

campaign_id
campaign_name

campaign_promotion

campaign_coupon

campaign_startdate

campaign_enddate


call_reason       (table that contains the following:)

reason_id
reason


store               (table that contains the following:)

store_id
store_number
store_address
store_city
store_state
store_postalcode
store_name

store_phone

store_email

store_mgr


training_points  (table that contains the following:)

training_key_id
key_issue

policy


example_type  (table that contains the following:)

example_id
example_name
example_image

Thank you very much.

This topic has been closed for replies.

1 reply

Lawrence_Cramer
Inspiring
July 18, 2009

Frankly, that is way to much of a question to be answered in detail on a forum... There's a lot involved and a lot of general database understanding required. I would highly recommend:

Database Design for Mere Mortals:                       A Hands-On Guide to Relational Database Design, Second                       Edition -- by Michael                     J. Hernandez

This is an invaluable book to get you going in the right direction and on a firm foundation.

--
Lawrence   *Adobe Community Expert*
www.Cartweaver.com
Complete Shopping Cart Application for
Dreamweaver, available in ASP, PHP and CF
www.twitter.com/LawrenceCramer