Jump to content

Help structuring tables


elementis0

Recommended Posts

Ok well im doing my first upload system for a website and im structuring a table that will get user information necessary to do what i want with it in later pages and im having trouble with one part first heres the code:

$tutorialcontent = "CREATE TABLE tutorial_content(page_id AUTO_INCREMENT;author varchar(75);date datetime NOT NULL default '0000-00-00 00:00:00'; tutorial_title tinytext NOT NULL;category varchar(75) NOT NULL;description tinytext NOT NULL;keywords tinytext NOT NULL;content longtext NOT NULL; )";$tutorialimage = "CREATE TABLE tutorial_image(page_id [what do i put here];tutorial_title tinytext NOT NULL;author varchar(75);image_type varchar(50) NOT NULL default '', image longblob NOT NULL, image_size bigint(20) NOT NULL default '0', image_name varchar(255) NOT NULL default '', image_date datetime NOT NULL default '0000-00-00 00:00:00', )";

for the page_id of the sql how do i make it so the page id of the tutorial_content table is ALWAYS that same is the sql for the page id of the tutorial_image table.is this possible to do with sql? if not, how would i go about achieving it in php?

Link to comment
Share on other sites

Well, when you add a register to one of the tables you'll have to add a register to the other one too to make sure they're always the same.I don't think you can link tables .

Link to comment
Share on other sites

Just make the column the same data type as the other column, so probably an int. You can set up a trigger on the tutorial_content table to insert a new row into the other table whenever a row gets inserted, you can use the same ID as the new row. Do a search for SQL triggers to learn about that. Or in PHP you can just insert a new row into the second table after you insert the row in the first table. If you're using MySQL then you can use the mysql_insert_id function to get the ID for the row you just inserted into the first table, and insert a row in the second table with the same ID. In both cases the ID column in the second table is not an autonumber, just a regular int.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...