asdx Posted November 5, 2006 Share Posted November 5, 2006 Hello.let me explain my problem, first of all, i have a <select name="local[]"> element with many <option> elements, and i have another <select name="visit[]"> element with many <option> elements.when i submit that data, it creates an array local and an array visit, with the data from the options on it. then i do something like: foreach($_POST['local'] as $element1 => $value1){} and foreach($_POST['visit'] as $element2 => $value2){}the problem is that i want to send $value1 and $value2 through a SQL (INSERT) query and i don't know how to do. Link to comment https://forums.phpfreaks.com/topic/26260-foreach-problem/ Share on other sites More sharing options...
asdx Posted November 5, 2006 Author Share Posted November 5, 2006 can someone give me a tip or something, it would be really nice, thank you. Link to comment https://forums.phpfreaks.com/topic/26260-foreach-problem/#findComment-120106 Share on other sites More sharing options...
InfamousX Posted November 5, 2006 Share Posted November 5, 2006 [code]<?php/*connect to mysql server and stuff*/ foreach($_POST['local'] as $local){ foreach($_POST['visit'] as $visit){ mysql_query("INSERT INTO table(local,visit) VALUES('$local', '$visit')"); } }?>[/code]Where is the problem :/ Link to comment https://forums.phpfreaks.com/topic/26260-foreach-problem/#findComment-120113 Share on other sites More sharing options...
ToonMariner Posted November 6, 2006 Share Posted November 6, 2006 Improvement on teh above...[code]<?php$qrystr = NULL; foreach($_POST['local'] as $local){ foreach($_POST['visit'] as $visit){ $qrystr .= "('$local', '$visit'),"; } }if (!is_null($qrystr)){ $qrystr = substr($qrystr,0,strlen($qrystr) - 1); $qry = mysql_query("INSERT INTO table(local,visit) VALUES " . $qrystr);}?>[/code]Only using one query then.... Link to comment https://forums.phpfreaks.com/topic/26260-foreach-problem/#findComment-120121 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.