0

Hi !
I’m new to php and try to devellop a simple application that would allow the user to classify various dishes by using radio buttons. I'm a bit lost :(

My code is as follows (I’ve already got help to achieve it, but can’t go further). The first part is correct. But the second one, which consists in showing the dishes in the corresponding section (eg:
Sugar:

  • ,

  • Slat:
  • ,

  • Spicy :
  • ), do not work.
  • Thank you very much for your help!!

  • Raf
<?php 

$dish = array('soup', 'starter', 'meal', 'dessert');

echo '<form action="" method="post">
<table>
  <tr>
    <th>Dish</th>
    <th>Sugar</th>
    <th>Salt</th>
    <th>Spicy</th>
  </tr>
';

foreach ($dish as $value){
echo '<tr>
  <td>'.$value.'</td>
  <td><input type="radio" value="sugar" name="dish['.$value.'][]" /></td>
  <td><input type="radio" value="salt" name="dish['.$value.'][]" /></td>
  <td><input type="radio" value="spicy" name=dish['.$value.'][]" /></td>
</tr>';
}
echo '<tr><td colspan="4"><input type="submit" name="env" value="submit" /></td></tr></table></form>';

?>

<strong> Sugar : </strong>

<?php /* From this point it doesn’t work any more*/
foreach($_POST['dish'] as $selection)
{
    echo($selection == "sugar") $value ;
}
?>
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Raf8
0

Hi! I expect it
1) to show a form that allows the user, for each element of the array (the dishes), to choose between sugar, salt or spicy
2) to show, under three static subtitles (wich are once again sugar, salt or spicy), wich dishes has been selected for each value

so the html form would be (this part is ok)

dishes | sugar | salt | spicy
soup | [radio] | [radio] | [radio]
starter|[radio] | [radio] | [radio]
meal | [radio] | [radio] | [radio]
dessert| [radio] | [radio] | [radio]

if the user would select soup: salt, starter, spicy, meal: spicy and dessert sugar, the output would be:
Sugar: dessert
Salt: soup
Spicy: starter, meal
This part does not work...

Thank you very much!!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.