我的脚本中有这个代码,它只显示我的第一行.. 有解决方案吗(这不是我的整个剧本)
$sql = mysql_query ('select * from todo');
if (!$sql) {
die('Invalid query: ' . mysql_error());
}
$taskrow = mysql_query ('select * from todo');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$taak = $_POST['taak'];
$beschrijving = $_POST['beschrijving'];
$categorie = $_POST['categorie'];
$prioriteit = $_POST['prioriteit'];
$datum = $_POST['datum'];
$query = mysql_query("INSERT INTO todo (taak, beschrijving, categorie, prioriteit, datum) VALUES ('$taak', '$beschrijving', '$categorie', '$prioriteit', '$datum')") or die(mysql_error());
} ?>
<?php $task = mysql_fetch_assoc($taskrow); ?>
<td><?php echo $task['taak']; ?></td>
<td><?php echo $task['beschrijving']; ?></td>
<td><?php echo $task['categorie']; ?></td>
<td><?php echo $task['prioriteit']; ?></td>
<td><?php echo $task['datum']; ?> </td>
答案 0 :(得分:6)
通过做:
$task = mysql_fetch_assoc($taskrow)
;
您正在将$task
转变为一个对象,其中包含数据库查询中所选行的数据。
所以,你需要遍历那个对象,以便玩每一行的数据...
所以试试:
while ($task = mysql_fetch_assoc($taskrow)){?>
<td><?php echo $task['taak'];?></td>
<td><?php echo $task['beschrijving']; ?> </td>
<td><?php echo $task['categorie']; ?></td>
<td><?php echo $task['prioriteit']; ?></td>
<td><?php echo $task['datum']; ?> </td>
<? } ?>
答案 1 :(得分:0)
<?php foreach($task as $key => $value) : ?>
<td><?php echo $value;?></td>
<?php endforeach; ?>