Page 1 of 1

Writing Data from a MySQL DB Into a Table

Posted: Wed May 01, 2002 3:03 pm
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!

Posted: Wed May 01, 2002 3:19 pm
by jason

Posted: Wed May 01, 2002 7:08 pm
by Jim
That's not how you stick it into HTML tables, though.

Do you have a tutorial over that, perhaps? Thanks amigo :)

Posted: Wed May 01, 2002 7:40 pm
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

Posted: Thu May 02, 2002 4:53 am
by Jim
Thanks Jason :)

I feel stupid ;)