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
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.

Link to comment
Share on other sites

	// 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";
	    }
	}

Link to comment
Share on other sites

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";
	}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.