I'm trying to figure out how to get the $_GET['checkTitle'.$b] into an array. $b indicates that they are numbered. for($b=0; $b<66;$b++){ if(!empty($_GET['checkTitle'.$b])){ $checkTitleArr=Array($_GET['checkTitle'.$b]); print_r($checkTitleArr); //$sql.= " AND"; //$sql.= " OR"; //$sql.= " book_title='".$_GET['checkTitle'.$b]."'"; } } PHP: What I'm getting so far is: When 2 books are checked in the <form>.
You are looping 65 times because u have 65 checkboxes? Try this, this is the basic idea. if (replace_with_your_submitted_check) { //unset input type="submit" name="submit" if necessary //unset($_POST['submit']); //if your form contain checkboxes only (beside submit button) $i = 0; // will be used for loop foreach ($_POST as $checkbox) { $checkTitleArr[$i] = $checkbox ; $i++; } // test result print_r($checkTitleArr); } // close your if (submitted) PHP:
Your script must have a part where u check if the form is submitted right? thats the part. an example: if( isset( $_POST['submit']) ) { if the form is submitted to a different file, you can skip that.
Do you have 66 checkboxes? And you want to go through them one by one? Then use this: <input type"checkbox" name=checkboxes[item1] value="1 "/> <input type"checkbox" name=checkboxes[item2] value="1 "/> <input type"checkbox" name=checkboxes[item3] value="1 "/> <input type"checkbox" name=checkboxes[item4] value="1 "/> HTML: $array_of_checkboxes=$_POST['checkboxes'] foreach($array_of_checkboxes as $name=>$value) { echo $name.' : '.$value;// example: item1: 1 } PHP:
What if I have an ajax code? checkTheTitle=document.getElementsByName('checkTitle[]'); //txt=""; for (i=0;i<checkTheTitle.length;++ i) { if (checkTheTitle[i].checked) { getKeyURL=getKeyURL + "&checkTitle=" + checkTheTitle[i].value; } } Code (markup): what happens to the getElementsByName('checkTitle[]');? Does it stay as is or change somehow?