0

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

    <?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 中编辑/删除它们。

4

2 回答 2

1

不确定这是否是一个答案,但它更干净并且可能不太容易出现问题:

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

希望有帮助:)

于 2012-08-04T22:59:33.000 回答
0

通过此行在最后一个回显之前更改

            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>';

引号有问题(嵌套的 " 和 ' )

于 2012-08-04T22:49:14.817 回答