我如何在表格中放置链接

我的网站上有一张表,它从数据库中获取数据,在表中我有一行删除按钮,我刚刚用 jQuery 使表可搜索,但现在我不知道如何保留删除按钮.


索引.php:


<!DOCTYPE html>

<html>

<head>

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <meta charset="utf-8">

    <meta name="description" content="Inventar">

    <meta name="author" content="Martin Eide Bjørndal">

    <!-- Latest compiled and minified CSS -->

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">

    <link rel="stylesheet" href="/src/css/style.css">

       <!-- jQuery library -->

       <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

        <!-- Popper JS -->

        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

        <!-- Latest compiled JavaScript -->

        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>


</head>

<body>


    <button class="back" onclick="window.location='../'">

      <img src="/src/icons/back.png">

    </button> <!-- Tilbake knapp -->


    <button class="ny_inventar" onclick="window.location='/admin/brukere/ny'">

      <img src="/src/icons/add.png">

    </button> <!-- Ny Bruker knapp -->

这是搜索脚本,问题出在添加链接的 while 循环中,我不知道如何让它工作。


杨魅力
浏览 130回答 3
3回答

绝地无双

你可以使用它<?phpinclude "../../src/fn/init.php";$output = "";if(isset($_POST["query"])){&nbsp; &nbsp; $search = $_POST["query"];&nbsp; &nbsp; $stmt = $conn->prepare("SELECT * FROM brukere WHERE fornavn LIKE CONCAT('%',?,'%') OR etternavn LIKE CONCAT('%',?,'%') OR id LIKE CONCAT('%',?,'%')");&nbsp; &nbsp; $stmt->bind_param("sss",$search, $search, $search);} else {&nbsp; &nbsp; $stmt=$conn->prepare("SELECT * FROM brukere");};$stmt->execute();$result=$stmt->get_result();if($result->num_rows>0){&nbsp; &nbsp; $output = "<thead>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>#</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Fornavn</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Etternavn</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Utskjekket</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Admin</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Slett</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </thead>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tbody>";&nbsp; &nbsp; while($row=$result->fetch_assoc()){&nbsp; &nbsp; &nbsp; &nbsp; $output .= "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["id"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["fornavn"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["etternavn"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["utskjekket"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["is_admin"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><a href=\"delete.php=".urlencode($row['id'])."\" onclick=\"return confirm('Er du sikker?');\">Slett</a> </td>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>";&nbsp; &nbsp; };&nbsp; &nbsp; $output .= "</tbody>";&nbsp; &nbsp; echo $output;} else {&nbsp; &nbsp; echo "<h3>No match found!</h3>";};

慕桂英3389331

标签a没有作为纯文本添加到字符串中output,您需要重写该行,正确地将字符串部分连接到变量部分。尝试更换:$output .= "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["id"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["fornavn"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["etternavn"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["utskjekket"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["is_admin"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".<a href="delete.php?id=<?php echo urlencode($row['id']); ?>" onclick="return confirm('Er du sikker?');">Slett</a>."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>";和:$output .= "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["id"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["fornavn"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["etternavn"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["utskjekket"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row["is_admin"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><a href='delete.php?id=".urlencode($row['id'])."' onclick='return confirm('Er du sikker?');'>Slett</a></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>";

慕神8447489

要允许 PHP 从表结果中回显 id,您只需简单地执行一个 php echo<a&nbsp;href="delete.php?id=<?&nbsp;echo&nbsp;$row['id'];&nbsp;?>"&nbsp;onclick="return&nbsp;confirm('Er&nbsp;du&nbsp;sikker?');">Slett</a>您不必在此阶段进行 url 编码,因为您只是简单地构建 a:link 的 href
打开App,查看更多内容
随时随地看视频慕课网APP