"; //error_reporting(E_ALL & ~E_NOTICE); include("navigation.php"); include("config.php"); // I'm assuming that dropdown 1_1 is the first one, 1_2 is the second one and so on. // subcat_1_1_1 is the first checkbox in the first dropdown in the first of the three sections. // subcat_1_1_2 is the second checkbox in that dropdown and so on. $name = $_POST['name']; $green = $_POST['green']; $eco = $_POST['eco']; $dfe = $_POST['dfe']; $cate = array(); foreach($_POST AS $key => $value) { if (is_int(strpos($key,"cattag"))) { $t = explode("_",$key); $a = $t[1]; $b = $t[2]; $c = $t[3]; $cate[$a][$b][$c] = $value; } } echo "
"; echo sizeof($cate); echo "
cate:
"; var_dump($cate); echo "
"; $categories = array(); foreach($_POST AS $key => $value) { if (is_int(strpos($key,"subcat"))) { $t = explode("_",$key); $a = $t[1]; $b = $t[2]; $c = $t[3]; $categories[$a][$b][$c] = $value; } } print "
categories dump
"; var_dump($categories); echo sizeof($categories); print "end categories dump
"; print "
"; // Now you have an array with all checkboxes, something like // $subcat[1][1][1] = The number of the first checked checkbox in the first category // $subcat[1][1][2] = The number of the second checked checkbox in the first category and so on. // $subcat[1][2][1] = The number of the first checked checkbox in the second category // $subcat[1][2][2] = The number of the second checked checkbox in the second category and so on. // $subcat[2][1][1] = The number of the first checked checkbox in the first category, second section // $subcat[2][1][2] = The number of the second checked checkbox in the first category, second section and so on. $key_exists = true; $subkey_exists = true; $strings = array(); // Loops through and turns all categories' arrays into strings foreach ($categories AS $key1 => $array1) { foreach ($array1 AS $key2 => $array2) { $strings[$key1][$key2] = implode(';', $array2); } } echo sizeof($strings); print "
strings start
"; var_dump($strings); print "
strings end

"; // Now strings[] contains all the strings (like 1;3;5 and 3;5;7). Loop through the array: foreach ($strings AS $key1 => $array1) { foreach ($value1 AS $key2 => $array2) { printf( "INSERT into item_new (name, green, eco, dfe, section, category, subcategory) VALUES ('%s','%s','%s','%s','%s','%s',';%s;')
", $name, $green, $eco, $dfe, $key1, $cate[$key1][1][$key2], $array2); } } // Done. // Store that field in the DB and then when you want them into an array again, do: // $array = exlode(';', $string); echo "Successfully Inserted info Database"; ?>