Skip to content Skip to sidebar Skip to footer

How To Pass Value Of For Loop From One Page To Next Page In Php?

hi everyone my problem is this that i dynamically creted rows of table on the basis user input. Now each row contain textbox,comboxbox on selcting value from combobox n entering va

Solution 1:

You need to be passing an array, you can deal with it as an array in the PHP side.

To do this, in each input, change the name="X" to name="X[]"

Example:

<inputtype="text"name="t2"id="in1-<?phpecho$i; ?>"onblur="getText3(<?phpecho$i; ?>)" />

to:

<inputtype="text"name="t2[<?phpecho$i; ?>]"id="in1-<?phpecho$i; ?>"onblur="getText3(<?phpecho$i; ?>)" />

Also, it's generally a bad idea to use @'s in php to suppress errors.

Try something like:

var_dump($_POST);

and you will see how the data comes through to you.

Hint:

if (isset($_POST['t1']) {
   $t1_data = $_POST['t1'];
}

** EDIT **

Try something like this:

<?phpif (isset($_POST['submit'])) {

    $data_t1 = $_POST['t1'];
    foreach ($data_t1as$key => $value) {

        echo'T1: ' . $value . '<br />';
        echo'T2: ' . $_POST['t2'][$key] . '<br />';
        echo'Username: ' . $_POST['username'][$key] . '<br /><br />';

    }

}
?><html><head><script>functiongetText3(row){
            var in1=document.getElementById('in1-' + row).value;
            var in2=document.getElementById('in2-' + row).value;
            var in4=document.getElementById('in4-' + row).value;
            var in3=(in1*in2*in4*30)/1000;
            document.getElementById('in3-' + row).value=in3.toFixed(2 );

        }
    </script></head><body><formaction=""method="POST"><tableborder="1"align="center"id="wr123"><tr><th>WAS</th><th>NO.</th><th>AVERAGE</th><th>APPROX</th></tr><?phpfor ($i = 1; $i < 4; $i++) {
    ?><tr><td>Tube</td><td><selectid="in4-<?phpecho$i; ?>"name="t1[<?phpecho$i; ?>] onclick="getText3(<?phpecho$i; ?>)" ><optionvalue="0">0</option><optionvalue="12">12</option><optionvalue="18">18</option><optionvalue="24">24</option><optionvalue="75">75</option></select></td><td><inputtype="text"name="t2[<?phpecho$i; ?>]"id="in1-<?phpecho$i; ?>"onblur="getText3(<?phpecho$i; ?>)" /></td><td><selectname="a1[<?phpecho$i; ?>]"id="in2-<?phpecho$i; ?>"onclick="getText3(<?phpecho$i; ?>)" ><optionvalue="0">0</option><optionvalue="1">1</option><optionvalue="2">2</option><optionvalue="3">3</option><optionvalue="4">4</option><optionvalue="5">5</option><optionvalue="6">6</option><optionvalue="7">7</option><optionvalue="8">8</option></select></td><td><inputtype="text"id="in3-<?phpecho$i; ?>"name="username[<?phpecho$i; ?>]"readonly="readonly" /></td><td></tr><?php } ?></table><inputtype="submit"name="submit"value="submit"></form></body></html>

Post a Comment for "How To Pass Value Of For Loop From One Page To Next Page In Php?"