1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

from $_GET['checkTitle'] into an array

Discussion in 'PHP' started by gilgalbiblewheel, Nov 4, 2008.

  1. #1
    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]."'";
    	}
    }
    What I'm getting so far is:
    When 2 books are checked in the <form>.
    SEMrush
     
    gilgalbiblewheel, Nov 4, 2008 IP
    SEMrush
  2. ads2help

    ads2help Peon

    Messages:
    2,148
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    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)
    
     
    ads2help, Nov 4, 2008 IP
  3. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    I don't understand this:
    replace_with_your_submitted_check
     
    gilgalbiblewheel, Nov 4, 2008 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,148
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #4
    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.
     
    ads2help, Nov 4, 2008 IP
  5. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #5
    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
    }
    
     
    rohan_shenoy, Nov 4, 2008 IP
  6. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #6
    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?
     
    gilgalbiblewheel, Nov 4, 2008 IP