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. Quote Link to comment 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. Quote Link to comment 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 :/ Quote Link to comment 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.... 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.