doutang7707 2019-05-27 18:07
浏览 96
已采纳

为什么我不能访问这个数组中的第二个元素,而循环问题

I have this while loops and an embedded if statement which places a hyperlink in the appropriate table cell. When I press edit the URL reflects what I want to see (which is the current word to be edited) but the text field the word is suppose to populate is only ever the first entry in the database table.

I have tried Using PHP variables inside HTML tags? which I think does not work because mine is an internal link, not another website.

I have also tried to store $row['yourword'] in another var, so when the while loop encounters that if statement which puts the edit in the right cell, it also would save the correct yourword, but it just results in an error.

Here is the while loop

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['uname'] . "</td>";
echo "<td>" . $row['clickrate'] . "</td>";
if($row['uname'] == $logedInUsername)
{
    echo "<td>" . $row['yourword'] . "<a href='edityourword.php?edit=$row[yourword]'> edit</a></td>";
}
else
{
    echo "<td>" . $row['yourword'] . "</td>";
}
echo "</tr>";
}
echo "</table>";
?>

And here is the destination

<form action="edityourword.php" method="POST">
    word: <input type="text" name="newName" value="<?php echo $row[yourword]; ?>"><br><br>
    <input type="submit" value="Update">    
</form>

The expected result should be the 2nd word showing up in the text field on the next page, instead of the first one each time, editing the word still works, but the text field is just populated with wrong one each time if it is not the user which is the first on the table.

PS. If visualising helps: table

  • 写回答

1条回答 默认 最新

  • dqjmq28248 2019-05-27 19:21
    关注

    You should get the value of 'edit' in your destination with : $_GET['edit'] since you are sending it as parameter in the link

    <a href='edityourword.php?edit=$row[yourword]'> edit</a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料