dennismonsewicz Posted December 12, 2008 Share Posted December 12, 2008 Is there a way to create a SQL statement that will insert into a database and the next SQL entry will grab the rowid of the first statement entered? Link to comment https://forums.phpfreaks.com/topic/136703-solved-dynamic-sql-statement/ Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 $query = "INSERT INTO `table` (`field`) VALUE ('something')"; $result = mysql_query($query) or die(mysql_error()); $insertid = mysql_insert_id(); Link to comment https://forums.phpfreaks.com/topic/136703-solved-dynamic-sql-statement/#findComment-713847 Share on other sites More sharing options...
timmah1 Posted December 12, 2008 Share Posted December 12, 2008 mysql_insert_id() Link to comment https://forums.phpfreaks.com/topic/136703-solved-dynamic-sql-statement/#findComment-713848 Share on other sites More sharing options...
timmah1 Posted December 12, 2008 Share Posted December 12, 2008 oops, sorry gevans Link to comment https://forums.phpfreaks.com/topic/136703-solved-dynamic-sql-statement/#findComment-713849 Share on other sites More sharing options...
dennismonsewicz Posted December 12, 2008 Author Share Posted December 12, 2008 hmm thanks for the help... i am writing a SQL file can you use this in the file? like: INSERT INTO `table` (`field1`) VALUE ('something'); INSERT INTO `table` (`field1`) VALUE ('something') WHERE mysql_insert_id(); Link to comment https://forums.phpfreaks.com/topic/136703-solved-dynamic-sql-statement/#findComment-713864 Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 You don't need a WHERE clause in an INSERT statement Link to comment https://forums.phpfreaks.com/topic/136703-solved-dynamic-sql-statement/#findComment-713883 Share on other sites More sharing options...
dennismonsewicz Posted December 12, 2008 Author Share Posted December 12, 2008 so my SQL could look like this INSERT INTO `table` (`field1`) VALUE ('something', 'somethingelse'); INSERT INTO `table` (`field1`) VALUE ('something', mysql_insert_id); Link to comment https://forums.phpfreaks.com/topic/136703-solved-dynamic-sql-statement/#findComment-713890 Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 mysql_insert_id is php, so its easier to write this in php $query = "INSERT INTO `table` (`field1`) VALUE ('something', 'somethingelse')"; $result = mysql_query($query) or die(mysql_error()); $returnid = mysql_insert_id(); $query = "INSERT INTO `table` (`field1`, `field2`) VALUE ('something', '$returnid')"; $result = mysql_query($query) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/136703-solved-dynamic-sql-statement/#findComment-713895 Share on other sites More sharing options...
dennismonsewicz Posted December 12, 2008 Author Share Posted December 12, 2008 ah gotcha... i am writing a Joomla (BOOOO) component and to install the file you have to write a sql file to install of the content and menu structure and its a pain in the butt. And the Joomla Forums suck! You can never get any help! Thanks for your help here man! Link to comment https://forums.phpfreaks.com/topic/136703-solved-dynamic-sql-statement/#findComment-713899 Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 no worries, hit resolved Link to comment https://forums.phpfreaks.com/topic/136703-solved-dynamic-sql-statement/#findComment-713902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.