php - Getting values stored in mutiple arrays. Checkboxes involved -


heloo,

i have following php code:

 <?php        $ratings = array(             1 => "all",             2 => "love",              3 => "hate",             4 => "maybe",             5 => "super" );  $question = array(             1 => "pizza",             2 => "prajitura",             3 => "placinta",  );    echo '<form method="post" action="' . $_server['php_self'] . '">';   echo '<p>how feel each topic?</p>'; foreach ($question $key=>$value){     echo "".$value."<br>";     echo "aici valoarea".$key;     $importhtml="";     foreach ($ratings $cheie => $raspuns) {          //   echo "cheie: ".$key."cheie raspuns:".$cheie."raspuns".$raspuns."\n";             $importhtml .= "$raspuns <input type='checkbox' name='i_".$key."_importance[] id='$raspuns' value='$cheie' />"; } echo "". $importhtml."<br>\n"; }   echo '<input type="submit" value="save questionnaire" name="submit" />';   echo '</form>';      if (isset($_post['submit'])) {   foreach ($question $key => $value) {     //if(isset( $_request["i_".$key."_importance"]))     $print="";      $importance = $_request["i_".$key."_importance"];      //var_dump($importance);      echo "cheie >".$key."<br>\n";     foreach($importance $cheie=>$valoare){         $print .="cheie".$cheie."valoare =".$valoare;         //echo "cheie".$cheie."valoare =".$valoare;         echo "<br>\n";     }     echo $print; }     }      ?> 

and wish retrieve values stored every array named i_$key_importance using foreach loop or loop. result not expected to. in i_$key_importance want store 0 value if client has not checked box , key value associative array ratings if has done so.

the expected outcome:

 $importance = $_request["i_".$key."_importance"]; $importance array containing { 1=> 1, 2=> 0 (here user hasn't selected option), 3=> 3, 4=> 0 (here user hasn't selected option), } 

the result stored in table id = key , corresponding column every answer contain 0 (if client hasn't selected answer) or number (if has selected answer).

any great appreciation,

you should maybe consider tag instead of regular checkboxes.

in order want checkboxes, can test if value returned checkbox equal value linked it, if not means user didn't check it.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -