Jump to content


Photo

getting an auto_incremented integer..


  • Please log in to reply
4 replies to this topic

#1 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 13 October 2006 - 06:34 AM

if you set your primary key as auto_incremented and you have a query "insert into table values('','{$var2}'...)", how can you save the newly saved primary key as a variable?

#2 extrovertive

extrovertive
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 13 October 2006 - 06:37 AM

$id = mysql_insert_id

#3 Toolmaster

Toolmaster
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 15 March 2008 - 04:26 AM

I know this thread is probably old, but I need help with Auto Increment.

This is the table I have created with auto_increment:


CREATE TABLE appointment(appointment_id MEDIUMINT NOT NULL AUTO_INCREMENT, Primary Key (appointment_id), student_id varchar(8), INDEX (student_id), FOREIGN KEY (student_id) REFERENCES student(student_id), lecturer_name varchar(50), INDEX (lecturer_name), FOREIGN KEY (lecturer_name) REFERENCES lecturer(lecturer_name), appointment_date DATE, appointment_time TIME) TYPE=INNODB;

Is the auto increment value also set as a primary key through Primary Key (appointment_id) or does it overide the primary key and its rules?

#4 Toolmaster

Toolmaster
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 15 March 2008 - 02:12 PM

Anyone?

#5 BlueSkyIS

BlueSkyIS
  • Members
  • PipPipPip
  • reallynotfakenews.com
  • 4,268 posts

Posted 15 March 2008 - 04:14 PM

auto increment and primary key are compatible and often used together so you don't have to manually increment the primary key.
deprecated (adj.) Used typically in reference to a computer language to mean a command or statement in the language that is going to be made invalid or obsolete in future versions.

Head Shops and Grow Stores and
Find Motorcycle/ATV Repair, Tires




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users