Heloo,
I have the 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 do you feel about each topic?</p>';
foreach ($question as $key=>$value){
echo "".$value."<br>";
echo "aici are valoarea".$key;
$importHtml="";
foreach ($ratings as $cheie => $raspuns) {
// echo "cheie: ".$key."cheie raspuns:".$cheie."raspuns".$raspuns."
";
$importHtml .= "$raspuns <input type='checkbox' name='i_".$key."_importance[] id='$raspuns' value='$cheie' />";
}
echo "". $importHtml."<br>
";
}
echo '<input type="submit" value="Save Questionnaire" name="submit" />';
echo '</form>';
if (isset($_POST['submit'])) {
foreach ($question as $key => $value) {
//if(isset( $_REQUEST["i_".$key."_importance"]))
$print="";
$importance = $_REQUEST["i_".$key."_importance"];
//var_dump($importance);
echo "cheie >".$key."<br>
";
foreach($importance as $cheie=>$valoare){
$print .="cheie".$cheie."valoare =".$valoare;
//echo "cheie".$cheie."valoare =".$valoare;
echo "<br>
";
}
echo $print;
}
}
?>
And I wish to retrieve values stored into every array named i_$key_importance using a foreach loop or a for loop. The result is not as I expected to. In the i_$key_importance i want to store 0 value if the client has not checked the box and the key value from associative array ratings if has done so.
The expected outcome:
$importance = $_REQUEST["i_".$key."_importance"];
$importance will be an array containing {
1=> 1,
2=> 0 (here the user hasn't selected an option),
3=> 3,
4=> 0 (here the user hasn't selected an option),
}
the result will be stored in an table with Id = key and corresponding column for every answer will contain 0 (if client hasn't selected an answer) or a number (if has selected an answer).
Any help great appreciation,