create a form from database contents

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jerry0258
Forum Newbie
Posts: 2
Joined: Sun Jan 22, 2012 9:02 pm

create a form from database contents

Post by jerry0258 »

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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: create a form from database contents

Post by califdon »

jerry0258 wrote:

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>";
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.
Remove the quotes from the $QueryResult line.

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>";
jerry0258
Forum Newbie
Posts: 2
Joined: Sun Jan 22, 2012 9:02 pm

Re: create a form from database contents

Post by jerry0258 »

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!
Post Reply