snakez Posted September 6, 2006 Share Posted September 6, 2006 Ey im just a newbie to php/mysql... i just like to ask a question regarding the sample queries below if i can assign/store a single (PHP)variable to all of it and how to do it.Insert Into Mytable1(fname,lname) values('nick','smith')Insert Into Mytable2(ProdID,ProdName) values('01','PC')Insert Into Mytable3(ORno,Date) values('01','01/01/01') Quote Link to comment Share on other sites More sharing options...
fenway Posted September 6, 2006 Share Posted September 6, 2006 If you mean run one query that does all 3, then no, not really... one insert per table per statement. Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 6, 2006 Share Posted September 6, 2006 fenway is correct, however, you [b]could[/b] possibly run all 3 queries from one mysql_query() call if that's what you're after. it's not advisable since you have no individual error tracking, but since it doesn't hurt to know options, here's an example:[code]<?php$code = "Insert Into Mytable1(fname,lname) values('nick','smith');Insert Into Mytable2(ProdID,ProdName) values('01','PC');Insert Into Mytable3(ORno,Date) values('01','01/01/01');";mysql_query($code);// a better option would be to store all the insert queries in one array// and loop through the array:$queries = array( "Insert Into Mytable1(fname,lname) values('nick','smith')", "Insert Into Mytable2(ProdID,ProdName) values('01','PC')", "Insert Into Mytable3(ORno,Date) values('01','01/01/01')");foreach ($queries as $q) { mysql_query($q);}?>[/code]with the second method, it's much more usable since you can break out of the loop with any given error and figure out what happened. hope this helps Quote Link to comment Share on other sites More sharing options...
fenway Posted September 6, 2006 Share Posted September 6, 2006 obsidian is correct as well... but I would refrain for "faking" multiple queries for a single call. In fact, I'm surprised that mysql_query() even lets you do this. It's much, much better to set up the array. Quote Link to comment Share on other sites More sharing options...
snakez Posted September 7, 2006 Author Share Posted September 7, 2006 Woohh... that was great guyz, thank you so much for the help... :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.