Jump to content

foreach problem


asdx

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.