•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,772 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1352 | Replies: 15 | Solved
![]() |
Thanks. I have found this code below for creating a table. I edited it to incorporate what was mentioned here previously. At the end, it has PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id), what exactly is this for? There was an short explanation, but it didn't make any sense to me. Also, there is no space after the ',' in the code. Is that correct? I think I would have a habit to put in a space if I wasn't just copying and pasting. Would that cause a problem?
$query="CREATE TABLE clients (id int(11) NOT NULL auto_increment,fname varchar(15) NOT NULL,lname varchar(15) NOT NULL,username varchar(20),email varchar(20),PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
mysql_query($query); UNIQUE and KEY id_2 isn't necessary, let alone primary key (id), indexes are meant to use a basic field for lookups, you could use more fields like fname and lname to perform special full-text lookups using MATCH().
And yes, you could avoid spaces or make carriage returns between commas to make the code more readable.
And yes, you could avoid spaces or make carriage returns between commas to make the code more readable.
Would this be the correct way to make the second table?
$query="CREATE TABLE food_journal (id int(11) NOT NULL auto_increment, id_client(11) NOT NULL, timestamp varchar(8) NOT NULL,water varchar(8) NOT NULL, breakfast varchar(8) NOT NULL, breakfast_calories int(8) NOT NULL, breakfast_time varchar(8) NOT NULL, snack_1 varchar(8) NOT NULL, snack_1_calories varchar(8) NOT NULL, snack_1_time varchar(8) NOT NULL, lunch varchar(8) NOT NULL, lunch_calories varchar(8) NOT NULL, lunch _time varchar(8) NOT NULL, snack_2 varchar(8) NOT NULL, snack_2_calories varchar(8) NOT NULL, snack_2_time varchar(8) NOT NULL, dinner varchar(8) NOT NULL, dinner_calories varchar(8) NOT NULL, dinner_time varchar(8) NOT NULL, snack_3 varchar(8) NOT NULL, snack_3_calories varchar(8) NOT NULL, snack_3_time varchar(8) NOT NULL";
mysql_query($query);
There is some little mistakes, like missing type on id_client field, a UNIX timestamp normally takes ten positions and lunch_time have one space inside (table names can't have any space). I recommend make the first field (id) as primary key usually.
The resultant SQL would be:
The resultant SQL would be:
CREATE TABLE food_journal( id INT( 11 ) NOT NULL AUTO_INCREMENT , id_client INT( 11 ) NOT NULL , TIMESTAMP INT( 11 ) NOT NULL , water VARCHAR( 8 ) NOT NULL , breakfast VARCHAR( 8 ) NOT NULL , breakfast_calories INT( 8 ) NOT NULL , breakfast_time VARCHAR( 8 ) NOT NULL , snack_1 VARCHAR( 8 ) NOT NULL , snack_1_calories VARCHAR( 8 ) NOT NULL , snack_1_time VARCHAR( 8 ) NOT NULL , lunch VARCHAR( 8 ) NOT NULL , lunch_calories VARCHAR( 8 ) NOT NULL , lunch_time VARCHAR( 8 ) NOT NULL , snack_2 VARCHAR( 8 ) NOT NULL , snack_2_calories VARCHAR( 8 ) NOT NULL , snack_2_time VARCHAR( 8 ) NOT NULL , dinner VARCHAR( 8 ) NOT NULL , dinner_calories VARCHAR( 8 ) NOT NULL , dinner_time VARCHAR( 8 ) NOT NULL , snack_3 VARCHAR( 8 ) NOT NULL , snack_3_calories VARCHAR( 8 ) NOT NULL , snack_3_time VARCHAR( 8 ) NOT NULL , PRIMARY KEY ( id ) )
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Hi, My Name Is Nubski (Visual Basic 4 / 5 / 6)
- php drop down menu to search multiple sql tables (PHP)
- Javascript/CSS Problem: Display is not properly hiding items (style.display="none") (JavaScript / DHTML / AJAX)
- IE works fine but Firefox doesn't display tables! (HTML and CSS)
- Why Use XHTML? (HTML and CSS)
- Large and tables/cells..how? (HTML and CSS)
- 200 GB Hard Drive Problems (Windows NT / 2000 / XP / 2003)
- C++ Relcat/Attrcat catalog help (C++)
Other Threads in the PHP Forum
- Previous Thread: js problem
- Next Thread: Sending a form via sendmail


Linear Mode