shaddf Posted August 23, 2015 Share Posted August 23, 2015 iam trying to get data from many input fields in a table based on their column position.they are also named based on their column position..if in the next column the input is empty, i should be able to track the previously full input and place its value instead. but so far it is always returning empty .where am going wrong with my code below $d=0; $arr=array(); while($d<$_POST['total']){ $d++; if($_POST['outcome'.$d]!==""){ $out=$_POST['outcome'.$d]; $act=$_POST['activity'.$d]; $ind=$_POST['indicator'.$d]; $tar=$_POST['target'.$d]; }else if($_POST['outcome'.$d]==""&& $_POST['activity'.$d]!==""){//$pos=$d #get the previously filled input for($fulo=$d;$fulo>0;$fulo--){ if($_POST['outcome'.$fulo] !==""){ $out=$_POST['outcome'.$fulo];break; }else{continue;} } $act=$_POST['activity'.$d]; $ind=$_POST['indicator'.$d]; $tar=$_POST['target'.$d]; } //} $arr[]= array($out,$act,$ind,$tar ); } Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 23, 2015 Share Posted August 23, 2015 (edited) i'm not sure what overall goal you are trying to accomplish based on your description and program logic (showing us what result you expect and what result you are actually getting from your code would be helpful), but making a series of numbered form field names - outcome1, outcome2, ... is not the easiest way of handling sets of form field data. use an array name instead - name='outcome[]' you can either leave the array index empty, which will result in sequentiality numbered indexes in the submitted array, or you can supply your own associative or numerical array indexes to tie each form field to specific meaning data on the server. Edited August 23, 2015 by mac_gyver Quote Link to comment Share on other sites More sharing options...
nik_jain Posted August 26, 2015 Share Posted August 26, 2015 Not tested, but in the last three lines in coded section $d should ( could ) be $fulo . for($fulo=$d;$fulo>0;$fulo--){ if($_POST['outcome'.$fulo] !==""){ $out=$_POST['outcome'.$fulo];break; }else{continue;} } $act=$_POST['activity'.$d]; $ind=$_POST['indicator'.$d]; $tar=$_POST['target'.$d]; and the else{continue;) is most probably not needed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.