html - Changing number of row's and column's with 2 dropdowns in PHP -


first of new php maybe stupid question, there go: have 2 dropdown select tags have following code in html , php:

     <select>         <option value="default">---a---</option>         <?php for($i=1; $i<+100; $i++) { ?>                 <option value="<?php $i ?>"><?php echo $i ?></option>         <?php } ?>      </select>       <select>         <option value="default">---b---</option>         <?php for($j=1; $j<=100; $j++) { ?>                 <option value="<?php $j ?>"><?php echo $j ?></option>         <?php } ?>      </select> 

then have table row , column (well @ least has changed mean):

    <table>                 <tr>                     <th>date</th>                     <th>temp</th>                     <th>nr a</th>                     <th colspan="2">a 1</th>                     <!--another th___nr a-->                 </tr>                 <tr>                     <td colspan="3"> </td>                     <th>something</th>                     <th>else</th>                     <!--another else___nr a-->                 </tr>                 <tr>                     <td>                         <?php                             //echo date(date_rfc822);                             echo date('js\, f\, y');                         ?>                     </td>                     <td>                         <input type="number" name="temp" placeholder="temp" />                     </td>                     <th>b 1</th>                     <td>                         <input type="number" name="something" placeholder="something" />                     </td>                     <td>                         <input type="number" name="else" placeholder="else" />                     </td>                     <!--another td___nr a-->                 </tr>                 <!--another tr___nr b-->             </table> 

what want first dropdown control number of a's (columns) , second dropdown number of b's (rows). possible php , if is, how?

i thinking of somehow memorize number choose in dropdown variable , for's resolve it, don't know how it, if possible.

thank in advance time helping me :)

php server side language, have post (a) , (b) inputs server use php construct relevant data used generate table want on page

<form action="index.php" method="post">     <!--put select elements here-->     <select name="columns"></select>     <select name="rows"></select>     <input type="submit" /> </form> 

then in top of php file

<?php     // using terniary operator here - can google     // ensures vars set 1 if there no post form     $columns = (isset($_post['columns'])) ? $_post['columns'] : 1;     $rows = (isset($_post['rows'])) ? $_post['rows'] : 1; ?> 

then in table

<table>     <?php foreach ($rows $row):?>         <tr>             <?php foreach ($columns $column):?>             <td></td>             <?php endforeach;?>         </tr>     <?php endforeach;?> </table> 

you enhance dieter suggested ajax, pure php you'll need this.

its basic example though, , need fleshing out fulfil more generating empty html table x columns , y rows.

edit: completed file should work. save code below line test.php , try out. can amend need.
sorry, made little mistake too, forgot convert posted data range used in foreach loop. that's corrected below

<?php // test.php      // using terniary operator here - can google     // ensures vars set 1 if there no post form     $c = (isset($_post['columns'])) ? $_post['columns'] : 1;     $r = (isset($_post['rows'])) ? $_post['rows'] : 1;      $columns = range(1, $c);     $rows = range(1, $r);  ?>   <form action="test.php" method="post">     <!--put select elements here-->     <select name="rows">         <option value="default">---a---</option>         <?php for($i=1; $i<+100; $i++) { ?>                 <option value="<?php echo $i ?>"><?php echo $i ?></option>         <?php } ?>      </select>       <select name="columns">         <option value="default">---b---</option>         <?php for($j=1; $j<=100; $j++) { ?>                 <option value="<?php echo $j ?>"><?php echo $j ?></option>         <?php } ?>      </select>     <input type="submit" /> </form>  <table>     <tr>         <?php foreach ($columns $column):?>         <th>temp head</th>         <?php endforeach;?>     </tr>     <?php foreach ($rows $row):?>     <tr>         <?php foreach ($columns $column):?>         <td>temp data</td>         <?php endforeach;?>     </tr>     <?php endforeach;?> </table> 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -