Jump to content

Help structuring tables


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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...