get auto_increment id

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

get auto_increment id

Post by shiznatix »

there is a auto incrementing id in this table. the id is called working_expierence_id. heres my query

Code: Select all

$query = '
            INSERT INTO
                mdl_cv_working_experience
                    (company_name, beginning_date, end_date,
                    fk_working_experiences_id,
                    fk_dd_job_category_id, fk_dd_occupation_id,
                    fk_dd_position_id, fk_dd_industry_id,
                    fk_dd_company_type, fk_dd_company_size)
            VALUES
                    ("'.$_POST[edit][company_name].'", "'.begin_date.'",
                    "'.end_date.'", "'.$work_exps_id[0].'", "'.$_POST[job_category].'",
                    "'.$_POST[occupation].'",
                    "'.$_POST[position].'", "'.$_POST[industry].'",
                    "'.$_POST[company_type].'", "'.$_POST[company_size].'")
        ';
inside that query i need to retreive the id that it makes when inserting those values and whatnot. how do i do that? i can not have a seperate query to get the id.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

If you're using mySQL, just use something like $id = mysql_insert_id(); immediately after the insert.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

many thanks
Post Reply