简体   繁体   English

如何在PHP中使用for循环打印表的数组格式数据?

[英]How to print the array format data of a table using for loop in php?

** * 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 * ** * 这是从数据库获取行数据成数组格式,我将数据数据放入变量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 * * ** 这里使用data1变量试图打印数据库中存在的所有行 *

                        <?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* * *这里是问题,我怎么能说它已经打印了第一行,然后在PHP echo语句中... on *

                              <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> 
                                   <? }

                                   }?>

Simple use the $i variable in th loop 在循环中简单使用$ i变量

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 } ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM