I am attempting to create a test in which the questions are contained in a database. I am retrieving the results of the query into an indexed array, but when I try to print them to the screen I get put into an infinite loop. My code is posted below:
include "dbconnect.php";
$SQLstring = "SELECT questiontext FROM test";
$QueryResult = "mysql_query($SQLstring, $con)";
echo "<form action=' ' method='post'>";
echo "<table width='100%' border = '1'>\n";
while(($Row = mysql_fetch_row($QueryResult)) !== FALSE)
{
echo "<tr><td>{$Row[0]}</td></tr>";
}
echo "</table>\n";
echo "</form>";
It seems to connect to the database but when looping through the array does not come to an end (it should pull 10 results from the database). Thank you for any help anyone can provide.
create a form from database contents
Moderator: General Moderators
Re: create a form from database contents
Remove the quotes from the $QueryResult line.jerry0258 wrote:It seems to connect to the database but when looping through the array does not come to an end (it should pull 10 results from the database). Thank you for any help anyone can provide.Code: Select all
include "dbconnect.php"; $SQLstring = "SELECT questiontext FROM test"; $QueryResult = "mysql_query($SQLstring, $con)"; echo "<form action=' ' method='post'>"; echo "<table width='100%' border = '1'>"; while(($Row = mysql_fetch_row($QueryResult)) !== FALSE) { echo "<tr><td>{$Row[0]}</td></tr>"; } echo "</table>\n"; echo "</form>";
While you're at it, remove the "!==FALSE" from the While line.
Code: Select all
include "dbconnect.php";
$SQLstring = "SELECT questiontext FROM test";
$QueryResult = mysql_query($SQLstring, $con);
echo "<form action=' ' method='post'>";
echo "<table width='100%' border = '1'>\n";
while($Row = mysql_fetch_row($QueryResult))
{
echo "<tr><td>{$Row[0]}</td></tr>";
}
echo "</table>\n";
echo "</form>";Re: create a form from database contents
Thank you so much! I had looked and looked at it until I had convinced myself that it was perfectly correct. I appreciate your help!