How best to store this table in MySQL and print it with PHP?

Discussion in 'PHP' started by ripcurlksm, Dec 7, 2010.

  1. #1
    I've searched the web trying to find examples of how to store tabular data in MySQL and loop through the rows to assemble a table using PHP, but no luck.

    Here is a sample of my Excel file that I want to insert into MySQL. I then want to display it with PHP/HTML in its tabular form.

    Keep in mind I have a lot of tables exactly like this for different countries so I am looking for a good MySQL schema to efficiently store this data, then have PHP make use of it by looping through the rows and id's to pull the correct data.

    1) How would you store this in MySQL?
    2) How would you loop through the database with PHP to build columns?

    [​IMG]
     
    ripcurlksm, Dec 7, 2010 IP
  2. nadeem3366

    nadeem3366 Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    Hi ripcurlksm,

    Do you want to store that data in MySQL directly from Excel file or want to store data in MYSQL like that one by one ?
     
    nadeem3366, Dec 7, 2010 IP
  3. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #3
    A couple questions:

    1. Will you be adding more years data to this in the future? Will you at some point add 2015 and then 2016?
    2. If adding more years, will years drop off? If/when you add 2015 will 2007 data no longer be needed?
    3. How is Growth Rate calculated?

    There's a right way to store this data, but based on your answers to the questions, the wrong way may be the way to go.
     
    plog, Dec 8, 2010 IP
  4. Nahid

    Nahid Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    CREATE TABLE IF NOT EXISTS data(
      id int(10) unsigned NOT NULL AUTO_INCREMENT,
      type varchar(30) NOT NULL,
      year year(4) NOT NULL,
      growth int(11) NOT NULL,
      PRIMARY KEY (id)
    )
    
    Code (SQL):
     
    Nahid, Dec 9, 2010 IP