user1889672
user1889672

Reputation: 161

PHP table only displaying one row

I have a problem in retrieving data from my MySQL table. My script only retrieves one row, which is the last row from my table, wherein the table contains 12 filled rows. My aim is to retrieve all rows in the table.

Here is the section of the code I believe the problem stems from:

<?php
//Grabs the whole queston list
$question_list="";
$sql = mysqli_query($link,"SELECT * FROM DebateQuestion") or die(mysql_error());;
$questionCount = mysqli_num_rows($sql);// count the output amount

if($questionCount>0){
while($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
$id = $row["qQuestionNo"];
$question = $row["qQuestion"];
$venue = $row["qDebateVenue"];
$date = $row["qDate"];
$question_list = "$id. $question&nbsp;&nbsp;&nbsp;<a href='#'>Edit</a> &bull;<a href='#'>Delete</a><br/>";
}
}else{
$question_list = "There are no questions in the inventory yet";
}

?>

Upvotes: 0

Views: 737

Answers (1)

Otto
Otto

Reputation: 929

Your error is here:

$question_list = "$id. $question&nbsp;&nbsp;&nbsp;<a href='#'>Edit</a> &bull;<a href='#'>Delete</a><br/>";

Make sure you append the text, not overwrite the previous value! Use .= to append strings:

$question_list .= "$id. $question&nbsp;&nbsp;&nbsp;<a href='#'>Edit</a> &bull;<a href='#'>Delete</a><br/>";

Upvotes: 2

Related Questions