forumnz Posted May 3, 2009 Share Posted May 3, 2009 Hey I have two arrays - one contains names and the other emails. An example might be "Array ([2] => Bob [5] => John) Array ([2] => [email protected] [5] => [email protected]) What would I do to insert multiple rows with that data so the names and emails go together? Thanks, Sam Link to comment https://forums.phpfreaks.com/topic/156614-solved-inserting-into-database-using-an-array/ Share on other sites More sharing options...
sKunKbad Posted May 3, 2009 Share Posted May 3, 2009 You would have to loop through your arrays, and create a database query while doing this looping. Link to comment https://forums.phpfreaks.com/topic/156614-solved-inserting-into-database-using-an-array/#findComment-824669 Share on other sites More sharing options...
forumnz Posted May 3, 2009 Author Share Posted May 3, 2009 So you mean do more than 1 query? I would rather do just 1. Is there a way to have something like: "INSERT INTO table (name, email) VALUES ('$arr_name[1]', '$arr_email[1]'), ('$arr_name[2]', '$arr_email[2]')........ etc Is that possible? Link to comment https://forums.phpfreaks.com/topic/156614-solved-inserting-into-database-using-an-array/#findComment-824670 Share on other sites More sharing options...
ngreenwood6 Posted May 3, 2009 Share Posted May 3, 2009 something like this: for($i = 0; $i < $array_length_goes_here; $i++) { $name = $array1[$i]; $email = $array2[$i]; $query = "INSERT INTO table (name,email) VALUES ('$name','$email')"; mysql_query($query); } Link to comment https://forums.phpfreaks.com/topic/156614-solved-inserting-into-database-using-an-array/#findComment-824671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.