首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php表格显示数据、编辑、删除

问php表格显示数据、编辑、删除
EN

Stack Overflow用户
提问于 2012-08-05 06:40:40
回答 2查看 1.5K关注 0票数 0

我花了一整天的时间试着让这个代码片段工作:

代码语言:javascript
复制
    <?php
            include("conn.php");

$result = mysql_query("SELECT * FROM users");
  echo "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" id=\"product-       table\">
  <tr>
  <th class=\"table-header-check\"><a id=\"toggle-all\" ></a> </th>
  <th class=\"table-header-repeat line-left\" ><a href=\"\">User ID</a></th>
  <th class=\"table-header-repeat line-left\"><a href=\"\"> Username</a></th>
  <th class=\"table-header-repeat line-left\"><a href=\"\">Firstname</a></th>
  <th class=\"table-header-repeat line-left\"><a href=\"\">Lastname</a></th>
  <th class=\"table-header-repeat line-left\"><a href=\"\">Email</a></th>
  <th class=\"table-header-repeat line-left\"><a href=\"\">Registration Date</a></th>
  <th class=\"table-header-options line-left\"><a href=\"\">Options</a></th>
   </tr>";
  while ($row = mysql_fetch_array($result)) {

   echo "<tr>";
   echo "<td>"."<input  type=\"checkbox\"/></td>";
    echo "<td>" . $row['user_id'] . "</td> ";
    echo "<td>" . $row['username'] . "</td>";
    echo "<td>" . $row['first_name'] . "</td>";
    echo "<td>" . $row['last_name'] . "</td>";
     echo "<td>" . $row['email'] . "</td>";
 echo "<td>" . $row['registration_date'] . "</td>";
 echo "<td class=\"options-width\">".
                "<a href=\"\" title=\"Edit\" class=\"icon-1 info-tooltip\">              </a>".
                "><a href="delete.php?id=' . $row['id'] . '"class=\"icon-2 info-tooltip\"></a>".
                "<a href=\"\" title=\"Save\" class=\"icon-5**strong text**info-tooltip\">       </a>".
                "
                </td>";
  echo "</tr>";
  }


     ?>

我想要做的是将我的用户拉到一个html表中,然后创建它,这样我就可以在url字符串ex中编辑/删除他们。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-05 06:49:15

通过此行更改上次回显之前的内容

代码语言:javascript
复制
            echo '<td class="options-width">'.
            '<a href="" title="Edit" class="icon-1 info-tooltip"> </a>'.
            '      <a href="delete.php?id=' . $row['id'] . ' " class="icon-2 info-tooltip"></a>'.
            '<a href="" title="Save" class="icon-5**strong text**info-tooltip">       </a>'.
            '</td>';

您在使用引号(嵌套引号“和‘)时遇到问题

票数 0
EN

Stack Overflow用户

发布于 2012-08-05 06:59:33

不确定这是否是答案,但它更简洁,也不太容易出现问题:

代码语言:javascript
复制
<?php
    include("conn.php");
    $result = mysql_query("SELECT * FROM users");
    $rows   = mysql_fetch_array($result);
?>
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
    <tr>
        <th class="table-header-check"><a id="toggle-all"></a> </th>
        <th class="table-header-repeat line-left"><a href="#">User ID</a></th>
        <th class="table-header-repeat line-left"><a href="#">Username</a></th>
        <th class="table-header-repeat line-left"><a href="#">Firstname</a></th>
        <th class="table-header-repeat line-left"><a href="#">Lastname</a></th>
        <th class="table-header-repeat line-left"><a href="#">Email</a></th>
        <th class="table-header-repeat line-left"><a href="#">Registration Date</a></th>
        <th class="table-header-options line-left"><a href="#">Options</a></th>
    </tr>
    <?php foreach($rows as $row) { ?>
    <tr>
        <td><input type="checkbox" /></td>
        <td><?php echo $row['user_id']; ?></td>
        <td><?php echo $row['username']; ?></td>
        <td><?php echo $row['first_name']; ?></td>
        <td><?php echo $row['last_name']; ?></td>
        <td><?php echo $row['email']; ?></td>
        <td><?php echo $row['registration_date']; ?></td>
        <td class="options-width">
            <a href="#" title="Edit" class="icon-1 info-tooltip"></a>
            <a href="delete.php?id=<?php echo $row['id']; ?>" class="icon-2 info-tooltip"></a>
            <a href="#" title="Save" class="icon-5 strong-text info-tooltip"></a>
        </td>
    </tr>
    <?php } ?>
</table>

希望这能有所帮助:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11812496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档