php - How do I write a code that produces a table of a party cost based on seven values? -
php – how write code produces table of party cost based on 7 values?
so example, if min , max 60 , cost1 5, cost2 10, cost3 15, cost4 20 , cost5 25
this should start.
//the (int) changes input integer, prevent code injection. //$_get takes variables url string, http://google.com?min=30&max=60 //$_post takes variables form on page gets submitted <input type="text" name="min" value="30" /> $min = (int) $_get['min']; $max = (int) $_get['max']; $costs = array( '5', '10', '15', '20', '25', ); echo '<table>'; for($i = $min; $i <= $max; $i++) { //if number divisible 5, show in table if($i % 5 === 0) { echo '<tr>'; echo '<td>' . $i . '</td>'; foreach($costs $cost) { echo '<td>' . $cost . '<br>' . $cost * $i . '</td>'; } echo '</tr>'; } } echo '</table>';
the resulting table be:
30 150 300 450 600 750
35 175 350 525 700 875
etc... , including 60.
Comments
Post a Comment