Jump to content

Content within a While loop isn't echoing


Runtheball

Recommended Posts

As a PHP learning exercise, I'm trying to program a "star trek" game. The game allows a list of commands, which are executed through a switch statement. The command below (case 8 ) is to 'scan an enemy vessel'. It should pull enemy vessel info from a database and display it in a table. The table border is all that appears...nothing is inside - no table rows, no table data.

 

case "8":
	    global $enemyType;
		if ($con)
		{	echo "Initiating scan, Captain.";
			echo "<br /><table class='tableData' width='66%' height='150px' cellpadding = '2'><tbody>";
			$query = "SELECT * FROM rom_warbird";
			$result = mysql_query($query) or die("Unable to retrieve scan data Sir");
			while($row=mysql_fetch_array($result, MYSQL_ASSOC))
			{
				$es1 = $row['0'];
				$es2 = $row['1'];
				$es3 = $row['2'];
				$es4 = $row['3'];
				$ews1 = $row['4'];
				$ews1Cond = $row['ews1Cond'];
				$ews1_stat = $row['ews1_stat'];
				$ee1 = $row['ee1'];
				$e_crew = $row['e_crew'];

				echo "<tr><td>$enemyType</td></tr>";
				echo "<tr><td><hr></td></tr>";
				echo "<tr><td>Shields at: " . $es1 . ", " . $es2 . ", " . $es3 . ", " . $es4 . "</td></tr>";
				echo "<tr><td>Weapon Systems include " . $ews1 . " , at " . $ews1Cond . " and " . $ews1_stat . " . </td></tr>";
				echo "<tr><td>Engines at " . $ee1 . " percent. </td></tr>";
				echo "<tr><td>She has a crew of " . $e_crew . " remaining.</td></tr>";
			}
			echo "</tbody></table><br />";
		}

		break;

 

The Firefox SGML parser reports "Error: end tag for "tbody" which is not finished" on the line of code where tbody first appears. According to the parser there are no table rows. In fact, nothing that I try to echo from within that while loop will actually echo. Echo statements inserted right up to the line before the while loop will echo.

 

What am I doing wrong?

I would highly reccommend starting with something a lot simpler for a learning exercise, starting this way could (and is) lead you into bad coding habits and database design. (You shouldnt have a table under the name of something you may later want to add, you should have references instead).

 

To your error:

 

I would imagine your html structure is not properly formatted before this code is called;

Give us the HTML source output of your page.

 

-cb-

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.