How to format mySQL data into an html table

I read http://www.phphelp.com/article/article.php?art=46 that page, but can’t figure out what the heck is going on, it gave me this error.

“Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host ‘DB_SERVER’ (11001) in C:Custom Programswampwwwphp_sandboxdbconnection.php on line 4
Sorry gangsta, the database connection failed: Unknown MySQL server host ‘DB_SERVER’ (11001)”

but dbconnection.php works in my other pages. anyways, in the code from that article, what do i change?

my database name is widget_corp and it connects through dbconnection.php, and in dbconstants.php are my username and password to connect to the database etc.

I have a table named subjects. Inside the table subjects i have 4 rows named ID MENU_NAME POSITION and VISIBLE

what do I replace with what in that articles code?

here’s the article code: [code]<?php

// load configuration

require(‘note-inf.php’);

// connect to db

require('db.php');







$sql = "SELECT item_name FROM items;";

		$result = mysql_db_query($db_name,$sql);

		

if (!$result || mysql_num_rows($result) < 1) {


			print mysql_error() . ' ERROR - SELECT note query failed! ';

		}

// get result into array

$col=0;

$rows=mysql_num_rows($result);

for ($i=0; $i<$rows; $i++) {

$arr[$i]=mysql_result($result,$i,$col);	

}

$i=0;

// break array over rows

print ‘

’;

while($i <= count($arr)) {

// row of five items

print '<tr>';

	for($r=1;$r<=5;$r++) {

	print '<td>'. $arr[$i] .'</td>';


	$i++;

	}

print '</tr>';

}

print ‘

’;

?>
[/code]

i’m just guessing:

the other script has a line like:
define(“DB_SERVER”, “localhost”);

this line is missing now.
a undefined constant defaults to containing the string of its name.
so leafing that line away is the same as using:
define(“DB_SERVER”, “DB_SERVER”);

now mysql_connect trys to find a sever called DB_SERVER.
that is not a vaild server name like “localhost”, “127.0.0.1” or “mysql.urdomain.com” would have been.

that makes mysql_connect fail.

plz look for a define(“DB_SERVER”,… in the working script.
if u find it copy that line to ur new script.

Sponsor our Newsletter | Privacy Policy | Terms of Service