PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
We have been racking our brains trying to figure out this one....maybe someone out there can help. We have a three list boxes that are all fed by mysql DB. When a choice in the first drop down list is chosen it populates the second and third list box with related choices.
In the second list box you can only choose one item (that works fine) but in the third list box we want to be able to select multilple items and pass those to the DB.
It kinda works...when you select multiple items (by holding down the Ctrl key) only the last item selected gets submitted to the DB!
How can we get all of the selected items to be submitted?
<?php
$sel_list = $_POST['multilist'];
if (is_array($sel_list))
{
foreach($sel_list as $key => $value)
{
echo "This multi key is $key and the value is $value...<br />";
}
}
?>
What is the passed $_POST['list_box_3'] value? If it is passing an array (which it should be doing seeing as it is coming from a multiple select list) then you would have to manipulate the array to get all the values from that element of the $_POST array. Can you show your DB update code so we can see what is happening at that point in your app?
$client_department_result = mysql_query("SELECT DISTINCT department_name FROM client_departments WHERE department_id='$department'") or die(mysql_error());
Insert new rows into the db with the survey form information
$add_survey = "INSERT INTO reports(client_department, request_date, originator, recipients, reason, status, serial_id, comments)
VALUES('$client_department', '$requestDate', '$originators', '$recipients', '$reason', '$status', '$serialID', '$comments')";
mysql_query($add_survey) or die(mysql_error());
// Format Recipient(s) section to include multiple selections
$recipients = $_POST['recipients'];
if(is_array($recipients))
{
foreach($recipients as $key => $value)
{
// Concatenate the string instead of overwrite it
$recipients .= "".$value.", ";
}
}
The dot concatenates the string instead of revaluating it for each loop, as it was doing in your code.
I can't believe it - a dot! well I guess that's better then what it could be - thanks!!!!
I feel that I should buy you drink - or something! never been to Fremont CA - been to Burlingame, Redwood a lot though I guess your right across the San Mateo bridge...maybe next time
Glad I could help. Yes, we're across the San Mateo bridge, then south a few miles. As for the drink, go get yourself a cold one and think of the things you could do with a '.' over the next few thousand lines of code.