Writing Data from a MySQL DB Into a Table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Writing Data from a MySQL DB Into a Table

Post by Jim »

I saw a tutorial on this somewhere, but can't seem to find it again. If anyone knows where I can find a tutorial like this, please tell me. Thanks a lot for your help!
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

That's not how you stick it into HTML tables, though.

Do you have a tutorial over that, perhaps? Thanks amigo :)
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

It works the same way though.

HTML is HTML. PHP doesn't care, doesn't even now that you are sticking it into a table.

Take this:

Code: Select all

$dbconn = mysql_connect("localhost", "username", "password");
$result = mysql_select_db("database_name", $dbconn);
if ( $result == false )
{
	echo mysql_error();
} else {
	$sql = "SELECT fname, lname, email FROM friends";
	$result = mysql_query( $sql );
	if ( $result != false )
	{
		while ( $data = mysql_fetch_assoc( $result ) )
		{
			echo 'Name: '.
			$dataї'fname'].' '.
			$data&#1111;'lname'].' (<a href="mailto:'.
			$data&#1111;'email'].'">'.
			$data&#1111;'email'].'</a> )<br />';
		&#125;
	&#125; else &#123;
		echo mysql_error();
	&#125;
&#125;
And make it this:

Code: Select all

$dbconn = mysql_connect("localhost", "username", "password");
$result = mysql_select_db("database_name", $dbconn);
if ( $result == false )
{
	echo mysql_error();
} else {
	$sql = "SELECT fname, lname, email FROM friends";
	$result = mysql_query( $sql );
	if ( $result != false )
	{
		echo '<table border="1">';
		while ( $data = mysql_fetch_assoc( $result ) )
		{
			echo '<tr><td>';
			echo 'Name: '.
			$data&#1111;'fname'].' '.
			$data&#1111;'lname'].' (<a href="mailto:'.
			$data&#1111;'email'].'">'.
			$data&#1111;'email'].'</a> )<br />';
			echo '</td></tr>
		}
		echo '</table>';
	} else {
		echo mysql_error();
	}
}
That code is from the tutorial.

I don't see how much more of a tutorial you need. However, if you feel their is more to talk about, let me know what specifically you would want to know. Otherwise, I don't see the need for a tutorial specifically covering how to display variables in a table. Whether those variables come from a MySQL query or someplace else isn't important. Makes no difference. :D
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

Thanks Jason :)

I feel stupid ;)
Post Reply