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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?