Current location: Hot Scripts Forums » Programming Languages » PHP » Dynamically create table from column in database


Dynamically create table from column in database

Reply
  #1 (permalink)  
Old 11-26-11, 07:29 AM
gunnerone gunnerone is offline
New Member
 
Join Date: Nov 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Dynamically create table from column in database

Hi

I am trying to create a project where people can create menus from recipes stored in a database.

I need to somehow create a table with days across the top which are determined from a table in my database:

Code:
DROP TABLE IF EXISTS `days`;
CREATE TABLE IF NOT EXISTS `days` (
  `DayID` int(11) NOT NULL auto_increment,
  `DayName` varchar(255) NOT NULL,
  `DateEntered` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `EventID` int(11) NOT NULL,
  `shortcode` varchar(6) NOT NULL,
  `deliveryDay` tinyint(1) NOT NULL,
  PRIMARY KEY  (`DayID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
I need to get the DayNames that correspond to an EventID (submitted by the user in a form above) and put them across the top of a table and the Mealtime type down the side of the table from this table:

Code:
DROP TABLE IF EXISTS `mealtime`;
CREATE TABLE IF NOT EXISTS `mealtime` (
  `mealtimeID` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY  (`mealtimeID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
Can anyone assist me in creating a dynamic table in such a way?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 11-26-11, 10:03 AM
alxkls alxkls is offline
Newbie Coder
 
Join Date: Nov 2011
Posts: 98
Thanks: 0
Thanked 9 Times in 9 Posts
now to be perfectly honest-im not too sure what you are trying to do, even after i read it... so a nit better explanation would be appreciated... on a side note-why dayname is a varchar 255?!?!? wouldnt it be easier to... you know put them as 1,2,3,4,5,6,7 and use those instead. that will massively improve the db size if it gets big. and even if you are making this is some unheard language-store the names in some array somewhere...
Reply With Quote
  #3 (permalink)  
Old 11-26-11, 03:58 PM
gunnerone gunnerone is offline
New Member
 
Join Date: Nov 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
More Detail::
I have changed my table structure to his.

weekID is grabbed from another table where it has an ID 1-52 and the week name Week 1-52.

dayID is grabbed from another table where it has an ID 1-7 and the day names monday through sunday.

mealtimeID is the ID of the meal from a meals tables where it has an ID 1-5 and description Breakfast, lunch etc.

recipeID is the ID of the recipe in the recipe table.

Table structure
ID
weekID
dayID
mealtimeID
recipeID

I need to grab the contents of the table with the relevant meals that correspond to the correct criteria. for example it would be laid out like this. The values of the header and sidebar are constant only the items in the middle change.

Code:
                      Monday         Tuesday       Wednesday......
Breakfast             

Lunch....
How would i fill in the blanks of the table above with the recipe title held in the recipe table which has an recipeid which corresponds to the id held in the menu table?
Reply With Quote
  #4 (permalink)  
Old 11-27-11, 02:56 PM
alxkls alxkls is offline
Newbie Coder
 
Join Date: Nov 2011
Posts: 98
Thanks: 0
Thanked 9 Times in 9 Posts
add a few entries to the database, dump them and upload them somewhere. it's almost impossible to follow someone elses logic if you can't see actual data.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create table name with user input faisals999 PHP 7 05-17-11 06:52 AM
Create table zenix PHP 2 10-24-09 12:09 PM
Syntax Error Nikas Database 4 05-15-08 10:48 AM
MYSQL database countll Database 2 06-19-07 04:20 PM
Create two mysql table zoliky Database 4 07-19-06 03:41 PM


All times are GMT -5. The time now is 08:57 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.