I have multiple arrays which I am passing to a file sales_process.php on the form submit action. The arrays are named like this : boards1 = {a , b , c}, boards2 = {b , c , d}, boards3 = {a , c , d} . . and so on (The values are not a,b,c,d). I am passing them through multiple 'multiple select boxes' in my form like this where a,b,c,d are my multiple select options :
for ($count=1;$count<10;$count++)
echo "<td>"."<select name='boards".$count."[]' multiple='multiple'>".showOptionsDrop($boards,$arr)."</select></td>";
Now when i pass them to the file sales_process.php, i want to convert these arrays into strings using implode function so that i can store them into my 'schools' table. In sales_process.php file, I am doing this:
for ($i=0;$i<$count;$i++) {
$board = implode(',',${'boards'.$i});
$query = "UPDATE schools SET board = '$board' where schoolcode = (some_no)";
$result = mysql_query($query) or die("Error in updating table :".mysql_error());
}
So in this way, every time my loop runs, the values of boardsX gets converted into string and gets stored in the table, where X is 1,2,3.... and so on.
The problem is the implode function is not working and giving error :
Warning: implode() [function.implode]: Invalid arguments passed in C:\xampp\htdocs\relationshipReport\sales_process.php on line 18
Now if you say that the variable ${'boards'.$i}
is not an array, i did this and found out that its giving me an array only :
$i=1;
var_dump(${'boards'.$i});
print_r(${'boards'.$i});
which gives the output as :
array(3) { [0]=> string(4) "CBSE" [1]=> string(4) "ICSE" [2]=> string(5) "IGCSE" }
Array ( [0] => CBSE [1] => ICSE [2] => IGCSE )
I hope my question is clear. Please help me in finding out whats going wrong in the implode function. If you don't understand the question, please mention it.
[
and]
, rather than their curly counterparts. Try fixing this and reporting back. :) – Spiritfyre Jul 6 '12 at 5:34$_POST['boards'.$i]
or$_GET['boards'.$i]
, depending how you sent the content from the form. – Spiritfyre Jul 6 '12 at 5:45