Jump to content

turning mysql table into html table


cody4camp

Recommended Posts

I know I'm doing it something right, but can someone tell me why only one table is showing up? Can you help me fix the issue?

 

Heres my code:

 

function showcoords()
{
	echo"J3st3r's CoordVision";
	$result=dbquery("SELECT alliance, region, coordx, coordy FROM ".DB_COORDFUSION."");
	dbarray($result);
	$fields_num = mysql_num_fields($result);

	echo "<table border='1'>";
	// printing table headers


	    echo "<td>Alliance</td>";
	    echo "<td>Region</td>";
	    echo "<td>Coord</td>";


	// printing table rows
	while($row = mysql_fetch_array($result))
	{
	    

	    // $row is array... foreach( .. ) puts every element
	    // of $row to $cell variable
	    foreach($row AS $Cell)
		     echo "<tr>";		    
		     echo "<td>".$row['alliance']."</td>\n";
		     echo "<td>".$row['region']."</td>\n";
		     echo "<td>".$row['coordx'].",".$row['coordy']."</td>\n";
		     echo "</tr>\n";
	    
	}
			echo "</table>";
	mysql_free_result($result);

}

 

I have 2 rows inserted into my coords table. Just frustrated and ignorant to php.

Link to comment
https://forums.phpfreaks.com/topic/220768-turning-mysql-table-into-html-table/
Share on other sites

function showcoords()
{
	echo"J3st3r's CoordVision";
	$result=dbquery("SELECT alliance, region, coordx, coordy FROM ".DB_COORDFUSION."");
	echo "<table border='1'>";
	// printing table headers

		echo "<tr>";
	    echo "<td>Alliance</td>";
	    echo "<td>Region</td>";
	    echo "<td>Coord</td>";
		echo "</tr>\n";

	// printing table rows
	while($row = mysql_fetch_array($result))
	{
	    
	    foreach($row as $Cell)
	    {
		     echo "<tr>";		    
		     echo "<td>".$row['alliance']."</td>\n";
		     echo "<td>".$row['region']."</td>\n";
		     echo "<td>".$row['coordx'].",".$row['coordy']."</td>\n";
		     echo "</tr>\n";
	    }
	}
			echo "</table>";
	mysql_free_result($result);

}

Done what you mentioned, and now it displays the same row 8 times.

	// printing table rows
	while($row = mysql_fetch_assoc($result))
	{
	    
	    foreach($row as $Cell)
	    {
		     echo "<tr>";		    
		     echo "<td>".$Cell['alliance']."</td>\n";
		     echo "<td>".$Cell['region']."</td>\n";
		     echo "<td>".$Cell['coordx'].",".$Cell['coordy']."</td>\n";
		     echo "</tr>\n";
	    }
	}

haha. my bad. try this:

 

	// printing table rows
	while($row = mysql_fetch_assoc($result)) {
		     echo "<tr>";		    
		     echo "<td>".$row['alliance']."</td>\n";
		     echo "<td>".$row['region']."</td>\n";
		     echo "<td>".$row['coordx'].",".$row['coordy']."</td>\n";
		     echo "</tr>\n";
	}

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.