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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.