简体   繁体   English

以表格形式以PHP形式显示数据

[英]Display data in tabular manner in PHP form

I want to do something like this.. 我想做这样的事情。

I have a update form in PHP, which contains around 15 fields, 我有一个PHP更新表格,其中包含大约15个字段,

I want to show some data in tabular manner while you open the page for update.. 打开页面进行更新时,我想以表格形式显示一些数据。

Senario: Senario:

If you want to update a record of a person on day to day basis, I have the feature with me to search out that person form database, and when you click on update data.. 如果您想每天更新一个人的记录,则可以使用该功能搜索该人的表单数据库,并单击更新数据。

it should show in a manner that, 它应以某种方式显示,

field1.....---------- field1 .....----------
field2.....---------- field2 .....----------
field3.....---------- field3 .....----------

and now, 现在,

for field4,5,6,7 用于字段4,5,6,7

if these fields contain the data then show in a table manner with fields 4,5,6,7 as coloums and no of rows depending upon the number of entries (should be non editable)(assume the case of multiple input) 如果这些字段包含数据,则以表格的形式显示,其中字段4,5,6,7作为列,行的数量取决于条目的数量(应不可编辑)(假设有多个输入)

then form will continue. 然后表格将继续。
field4.....-------- field4 .....--------
field5.....-------- field5 .....--------
field6.....-------- field6 .....--------
field7.....-------- field7 .....--------

typically these field(4,5,6,7) gets their value update frequently and I have to maintain the previous inputs also. 通常,这些字段(4,5,6,7)会经常更新其值,我也必须保持先前的输入。

help me out with some solution, as I am unable to figure out how to do this? 请帮我解决问题,因为我不知道该怎么做?

before that i was using this.. here i was having a form field which can generate 5 options, and will populate the fields with data if u have entered before, now i want to change the display as I don't want user to play with the old data, so I want to show old data into a table and enter new data via a simple text field, 在此之前,我使用了此方法..在这里,我有一个可以生成5个选项的表单字段,如果您之前输入过该字段,则会在其中填充数据,现在我想更改显示,因为我不想用户玩使用旧数据,因此我想将旧数据显示到表中并通过简单的文本字段输入新数据,

as their is no point to keep these multiple input form field as user is updating only one value at a time. 因为用户一次只更新一个值,所以保留这些多个输入表单字段是没有意义的。

<script>
                    function Submitted_Date(value,object)
                    {
                    value = document.getElementById("subdate_num").value;
                    if (value > -1) {
                    var input= new Array(value);
                    var p;
                    //alert("Enter The fields You Know ");


               var ele = document.getElementById("subdate");

              if(ele.hasChildNodes())
              {
              var len = ele.childNodes.length;
              while(ele.childNodes.length - value > 1)
             {
                ele.removeChild(ele.lastChild);
             }
             }

          for (var i=len-1;i<value;i++)
                    {
                        p= i+1;
                        input[i] = document.createElement('div');

                        input[i].innerHTML = 'Submitted_Date' + p + ':  &nbsp;&nbsp; <input type="text" value="" name="subdate' + p + '" id="subdate' + p +'" size = 25 onclick="javascript: showCalendar("Submitted_Date'+ p +'")"/>';
                                    document.getElementById("subdate").appendChild(input[i]);
                                    var subdate = 'subdate' + p;



                    }
              }
              document.getElementById("subdate1").focus();

                    }
                    </script>


                    <tr>
    <td> Submitted Date  : 
        <select name="subdate_num" id="subdate_num" onChange="return Submitted_Date(this.value,this.form)">
          <?php
  for ($i=0;$i<=5;$i++)
  {
    if ($i==0) { $temp = "<option value=$i> - </option>"; echo $temp; }
    else { $temp = "<option value=$i>$i</option>";
    echo $temp; }
  }
  ?>
        </select></td>
      </tr>
    </table>
<table>

I think this is what you want, this will show the information in a table with as many (or few) columns as you want 我认为这就是您想要的,这将在表中显示您想要的(或更少)列的信息

$query = "SELECT * FROM announcements ORDER BY announceid";
$result = mysql_query($query);

echo "<table border='1'>
<tr>
<th>Announcement ID</th>
<th>Announcement Name</th>
<th>Announcement Category</th>
<th>Approved?</th>
<th></th>
</tr>";

if ($result && mysql_num_rows($result) > 0) {
$x = 0;
while ($row = mysql_fetch_array($result)) {

 echo "<tr>";
  echo "<td>" . $row['announceid'] . "</td>";
  echo "<td>" . $row['title'] . "</td>";
  echo "<td>" . $row['category_name'] . "</td>";
 echo "<td>" . $row['status'] . "</td>";
  echo '<td><a href="edit.php?announceid='.$row['announceid'].'">Edit</a></td>';
  echo "</tr>";
$x ++;
};

  echo "</table>";

Let me know if that is what you are looking for, or if there is any other way I can help. 让我知道这是否是您要寻找的,或者是否有其他我可以帮助的方式。 Thanks! 谢谢!

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

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