我想获取表的id并将其变为变量,以便我可以在链接中使用它。
但我收到通知:数组到字符串转换。
$getpID = "SELECT id from posts";
$res = mysqli_query($conn, $getpID) or die(mysqli_error());
$pid = mysqli_fetch_assoc($res);
<a id='del' href='deletepost.php?del=$pid'>Delete</a>
&#13;
这只是我遇到问题的代码的一部分。
答案 0 :(得分:1)
你需要这样做: -
<?php
$getpID = "SELECT id from posts";
$res = mysqli_query($conn, $getpID) or die(mysqli_error($conn));
while($pid = mysqli_fetch_assoc($res)){
echo "<a id='del' href='deletepost.php?del=$pid['id']'>Delete</a><br/>";
}
注意: - 这是因为$res
是result-set array object
,其值大于或等于1。所以你需要像这样迭代。
答案 1 :(得分:0)
$pid
是一个数组,您需要从数组中访问ID,然后才能在链接中使用它。
例如:
$id = $pid['id'];
<a id="del" href="deletepost.php?del=$id">Delete</a>