Simplyfy HTML Table code using PHP -
i have webpage (created within php files) needs display table 30 rows long , allows user enter values each of 30 rows , press button let php process have entered.
anyway instead of having write out normal html form table has 30 rows wonder if way create table in php less code.
so looks like
<form name="createtable" action="?page=createtable" method="post" autocomplete="off"> <table border='1'> <tr> <th> weight </th> <th> cbm min </th> <th> cbm max </th> <th> min </th> </tr> <tr> <th> 1000 </th> <th> 0.1 </th> <th> 2.3 </th> <th> <input type=text name=min1> </th> </tr> <tr> <th> 1500 </th> <th> 2.31 </th> <th> 3.5 </th> <th> <input type=text name=min2> </th> </tr> <tr> <th> 2000 </th> <th> 3.51 </th> <th> 4.6 </th> <th> <input type=text name=min3> </th> </tr> ..... + 27 more rows </table> </form>
i writing out complete table above, values weight, cbm min , max not increasing @ standard rate normal loop not work guess, these values put array perhaps? php rusty
here possible solution.
/* should contain rows, resultset database, or wherever data */ $rows = array( array( 'weight' => 1000, 'cbm_min' => 0.1, 'cbm_max' => 2.3 ), array( 'weight' => 1500, 'cbm_min' => 2.31, 'cbm_max' => 3.5 ), array( 'weight' => 2000, 'cbm_min' => 3.51, 'cbm_max' => 4.6 ) ); ?> <form name="createtable" action="?page=createtable" method="post" autocomplete="off"> <table border='1'> <tr> <th> weight </th> <th> cbm min </th> <th> cbm max </th> <th> min </th> </tr> <?php $i = 1; // i'll use increment input text name foreach ($rows $row) { /* happening inside foreach loop many records/rows in $rows array. */ ?> <tr> <th> <?= (float) $row['weight'] ?> </th> <th> <?= (float) $row['cbm_min'] ?> </th> <th> <?= (float) $row['cbm_max'] ?> </th> <th> <input type=text name="min<?= (float) $i ?>"> </th> </tr> <?php $i++; } ?> </table> </form> <?php // continue executing php
Comments
Post a Comment