0

***Here Is My Code****

           <form name="f1" method="post" action="middle1.php"> 

*Here It Is Getting The Row Data From DB into array format and i placed dat data into variable data1***

                              <?
                              $user=$_SESSION['user'];
                              $data1= array();
                              $data1= $obj->pcode($user);
                              $dat=  count($data1);
                              // echo $dat;
                              ?>

***Here Using The data1 variable am trying to print the all rows present in the DB*

                        <?if($data1!=''){
                                   for($i=0;$i<=$dat;$i++){
                                 ?>
                         <tr> <td width="52" height="28" align="center"bgcolor="#E1E1E1" class="cal_txt_black">

*Here is the problem how can i mention that it hav to print the first row then so...on in the php echo statement**

                              <input name="pcode" type="" value="<? echo $data1['projectcode']; ?>" size="1"  border="0" style="background-color:D8D8D8"></td>
                                <td width="52" height="28" align="center" bgcolor="#ffffff" class="cal_txt_black" style="border-right:1px solid #D8D8D8;"><input name="mon" type="text" value="<? echo $data1['mon']; ?>" size="1"  border="0" style="background-color:White"></td>
                                    <td width="52" height="28" align="center" bgcolor="#ffffff" class="cal_txt_black"><input name="tue" type="text" value="<? echo $data1['tue']; ?>" size="1"  border="0" style="background-color:White"></td>
                                    <td width="52" height="28" align="center" bgcolor="#ffffff" class="cal_txt_black"><input name="wed" type="text" value="<? echo $data1['wed']; ?>" size="1"  border="0" style="background-color:White"></td>
                                    <td width="52" height="28" align="center" bgcolor="#ffffff" class="cal_txt_black" ><input name="thu" type="text" value="<? echo $data1['thu']; ?>" size="1"  border="0" style="background-color:White"></td>
                                    <td width="52" height="28" align="center" bgcolor="#ffffff" class="cal_txt_black"><input name="fri" type="text" value="<? echo $data1['fri']; ?>" size="1"  border="0" style="background-color:White"></td>
                                    <td width="52" height="28" align="center" bgcolor="#ffffff" class="cal_txt_black"><input name="sat" type="text" value="<? echo $data1['sat']; ?>" size="1"  border="0" style="background-color:White">
                                            <td width="52" height="28" align="center" bgcolor="#ffffff" class="cal_txt_black" style="border-right:1px solid #D8D8D8;"><input name="sun" type="text" value="<? echo $data1['sun']; ?>" size="1"  border="0" style="background-color:White"></td>

                                            <td width="52" height="28" align="center" bgcolor="#D8D8D8" class="cal_txt_black" style="border-right:1px solid #ffffff;" ></td>
                                            <td width="52" height="28" align="center" bgcolor="#D8D8D8" class="cal_txt_black" style="border-right:1px solid #ffffff;"></td>
                                            <td width="52" height="28" align="center" bgcolor="#D8D8D8" class="cal_txt_black" style="border-right:1px solid #ffffff;"></td>


                               <td><input name="save1" class="btn_login" type="submit" value="Save" align="center" formaction="middle2.php"></td>         
                            </tr>
                               </form> 
                                   <? }

                                   }?>

1 Answer 1

1

Simple use the $i variable in th loop

for($i=0;$i<=$dat;$i++){
  ?>

<input name="pcode" type="" value="<?php echo $data1[$i]['projectcode']; ?>" size="1"  border="0" style="background-color:D8D8D8"></td>


<?php } ?>
Sign up to request clarification or add additional context in comments.

5 Comments

can you do print_r($data1) and paste value here?
it is printing first row but problem is am unable to loop it to print the remaining..
no need of loop just print $data1 before loop and paste the array here
Array ( [0] => employee [username] => employee [1] => PAP [projectcode] => PAP [2] => 6 [mon] => 6 [3] => 7 [tue] => 7 [4] => 8 [wed] => 8 [5] => 8 [thu] => 8 [6] => 10 [fri] => 10 [7] => 90 [sat] => 90 [8] => [sun] => )
Also one suggestion for using valid html as some time it may generate problems. (You must use put all you tr code between table block. Also it is better if you put closing form tag outside loop, Because in current scenario it can be skipped if no rows found)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.