我最近的项目中出现了更多错误(之前发布了另一件事)。
几天来我一直在努力解决这个错误。 PHP 不是我的主要编程语言,我也不擅长它。
我知道也不应该使用mysql_*
。
无论如何。这是代码片段。
<?php
$query = "SELECT * FROM events";
$result = mysql_query($query);
$content = array();
$num = mysql_num_rows($result);
if ($num > 0) {
while($row = mysql_fetch_assoc($result)) {
$content[$row['ID']] = $row;
}
}
if ($num > 0) {
?>
<thead>
<tr>
<th><?php echo implode('</th><th>', array_keys(current($content)));?></th><th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($content as $tablerow): ?>
<tr>
<td><?php echo implode('</td><td>', $tablerow);?>
</td><td><div class="btn-group" role="group" aria-label="Actions"><a class="btn btn-primary" role="button" href="#">New Session</a><a class="btn btn-success" role="button" href="#">Continue Latest</a><a class="btn btn-warning" role="button" href="#">Settings</a><?php echo "<a class='btn btn-danger' role='button' href='/manager/delete?id=".$row."'>Delete</a>"; ?>
</tr>
<?php endforeach; ?>
</tbody>
对 derp 格式化感到抱歉。无论如何。
我正在尝试将 delete
按钮链接到 ../manager/delete?id=x
,其中 x 是该行的 ID。我的数据库的格式是 ID 位于标有“ID”的列中。我试图通过此 ID 引用每一行...为什么这不起作用?
我也尝试过(代替row
),content[row['ID']]
,content['ID']
, 'row['ID']`,ID 上的大小写不同(大写/小写)。
最佳答案
Fred -ii- 的上述评论是正确的。
我已经尝试了除 $tablerow['ID']
以外的所有方法....现在你知道我猜的了。
谢谢大家的帮助。我在调试时错过的最愚蠢的事情之一......
关于php - 多维数组,但我无法检索数据 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29785541/