I have this two arrays, which come both from some checkbox selections and they are:
$date=$_REQUEST['date'];
$pdv=$_REQUEST['checkbox'];
The first array lists some dates, what i need is to loop therough the dates, and insert pdv values selected for that date in the database, something like:
[date] [1] => [pdv] [1]
=> [pdv] [2]
=> [pdv] [3]
[date] [2] => [pdv] [1]
=> [pdv] [2]
Then i will have this loop which will permit me to insert in the database valus :
[date] [1] - [pdv] [1] ; [date] [1] - [pdv] [2];
I thought of using this foreach but i am not that professional with php.. here’s where i’m asking for your help..
foreach($date as $val) {
foreach ($checkbox as $pdv) {
$values_arr[] = "('" . $val . "','" . $pdv . "')";
}
$values = implode(", ", $values_arr);
$sql="INSERT INTO date (att_id,date) VALUES $values";
mysql_query($sql)or die(mysql_error());
}
There are many useful functions here, try some of them:
http://php.net/manual/en/ref.array.php
Like this one:
http://php.net/manual/en/function.array-combine.php
And use print_r for view result array: