All pastes #942776 Raw Edit

Unnamed

public php v1 · immutable
·published 2008-03-14 19:05 UTC
rendered paste body
<?php var_dump($_POST);  print "GO!<br>"; //error_reporting(E_ALL & ~E_NOTICE);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.  $categories = array();$name = $_POST['name'];$green = $_POST['green'];$eco = $_POST['eco'];$dfe = $_POST['dfe'];print ("Name: $name<br>");print ("$green<br>");print ("$eco<br>");print ("$dfe<br>"); // Just a little trick to make multiple variables on a single line$section_exists = true;$category_exists = true;$subcategory_exists = true;//echo "catexists: $category_exists<br>secexists: $section_exists<br>subcatexists: $subcategory_exists<br>";  // While the array-key exists, this loop will run and collect all checkboxes// in the array called categories  print "START<br>"; for($w=1;$w<500;$w++){ echo "loop1<br>";        if(!array_key_exists('subcat_'.$w.'_1_1', $_POST))        { echo "loop2<br>";                //$w = -1;				break;        }               for($x=1;$x<500;$x++)        { echo "loop3<br>";                if(!array_key_exists('subcat_1_'.$x.'_1', $_POST))                { echo "loop4<br>";                        //$x = -1;						break;                }                       for($y=1;$y<500;$y++)                {  echo "loop5<br>";                        if(!array_key_exists('subcat_1_'.$x.'_'.$y, $_POST))                        {   echo "loop6<br>";                                    // $y = -1;							   break;                        }                         echo "loop7<br>";                                $categories[$w][$x][] = $y;                                        }        }}print_r ($categories);print "<br> TOP1<br>";  // 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.  print "MIDDLE1<br>" ;  $key_exists = true;$subkey_exists = true;$strings = array();// Loops through and turns all categories' arrays into strings for($h=1;$h<500;$h++){ echo "loop8<br>";       if(!array_key_exists($h, $categories))        { echo "loop9<br>";                //$key_exists = false;				break;        }				if (!array_key_exists(0, $categories[$h]))		    { echo "loop10<br>";                //$key_exists = false;				break;        }               for($i=1;$i<500;$i++)        { echo "loop11<br>";                if(!array_key_exists('['.$h.']['.$i.']', $categories))                { echo "loop12<br>";                        //$subkey_exists = false;						break;                }								print(sizeof($strings));				echo "<br>";				                // This will turn the array into a string with all subcategories, separated by ;.                // For example, 0;3;53 if subcategory 0, 3 and 53 are checked                $strings[$h][$i] = implode(';', $categories[$h][$i]);				echo "<br>";				echo implode(';', $categories[$h][$i]);				echo "<br>";        }		}  print "MIDDLE2<br>"; // Now strings[] contains all the strings (like 1;3;5 and 3;5;7). Loop through the array:for($x=1;$x<sizeof($strings);$x++){ echo "loop13";        for($y=1;$y<sizeof($strings[$x]);$y++)        { echo "loop14";                // *build a query using the string*                // Echoing just for debugging or whatever.               print("INSERT into item_test (id, name, green, eco, dfe, category, subcategory) VALUES ('','$name','$green','$eco','$dfe','$x','$y')");        }}  print "END<br>";  // Done. // Store that field in the DB and then when you want them into an array again, do:// $array = exlode(';', $string);print_r($strings);print "<br>"; ?>