I’ve got this code in my script, and it’s only showing me the first row..
Any solutions? (This is NOT my whole script)
$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>
By doing:
$task = mysql_fetch_assoc($taskrow);You are turning
$taskinto an object, containing data from the rows selected in your DB query.So, you need to loop through that object, in order to play with each row’s data…
So try: