本文介绍了如何在php中获取所选表项的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该从表中获取 id 来发出请求.但我是这样做的.

I should get id from a table to make a request. But I did it in this way.

我的桌子:id(AI);name(Varchar);authir(varchar);category(varchar);

My table :id(AI);name(Varchar);authir(varchar);category(varchar);

我想如果有任何解决方案可以让我感谢我的问题出现在这一行中:

I think if there any solutions to make that thank you my problem appears in this lines:

Print  "<td><a href='editt.php?id=$id'>edit</a> </td>";
Print  "<td>  <a href='delete.php?id=$id'>delete</a> </td>";

完整代码:

 <table class="table table-hover">
    <thead>
      <tr>
        <th>Book name</th>
        <th>Author</th>
        <th>Category</th>
        <th><th>
                <th><th>

        </tr>
    </thead>
    <tbody>

<?php

    $id = 0;
    while($info = mysql_fetch_array($data)) {
        $id++;
        Print "<tr>";
        Print" <td>".$info['name']."</td>";
        Print "<td>".$info['author']."</td>";
        Print  "<td>".$info['category']."</td>";
        Print  "<td>  <a href='editt.php?id=$id'>edit</a> </td>";
        Print  "<td>  <a href='delete.php?id=$id'>delete</a> </td>";
        Print " </tr>";

    }

?>

我想知道是否还有其他方法可以使用所选行的当前 id 进行重定向 id=$id如果编辑或删除链接中的指针 ID 为 =2,但实际上在 db 中为 3

I wondered if there are some other ways to make redirect with current id of selected row id=$idCan you look photo there if pointer in edit or delete link link id is =2 but actually in db it is 3

推荐答案

如果你能展示表格结构和完整的 php 代码,我们可以提供更多帮助,但就目前而言,你似乎应该:

if you can show the table structure and full php code we can help more, but just for now it seems you should just:

while($info = mysql_fetch_array($data)) {
    Print "<tr>";
    Print" <td>".$info['name']."</td>";
    Print "<td>".$info['author']."</td>";
    Print  "<td>".$info['category']."</td>";
    Print  "<td>  <a href='editt.php?id=".$info['id']."'>edit</a> </td>";
    Print  "<td>  <a href='delete.php?id=".$info['id']."'>delete</a> </td>";
    Print " </tr>";
}

并停止使用 mysql_* 函数,它已被弃用.您应该使用 mysqli 或 PDO.

And stop using mysql_* functions, It is deprecated. You should use mysqli or PDO.

这篇关于如何在php中获取所选表项的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 21:32