Page 1 of 1

MySQL n00b seeks help!

Posted: Wed Aug 27, 2003 2:58 pm
by edg
I've only just started using MySQL with PHP :oops: and I've got some problems with the source code below. Can anyone spot the problem? It's very messy because I'm trying to find out what's wrong...

Code: Select all

if ($db = mysql_connect("localhost", "block", "block")) {

echo ("Connected");
} else {
echo ("error");

}


mysql_select_db("test", $db);


	$result = mysql_query("SELECT COUNT(*) FROM users", $db);
	$rows = mysql_result($result,0,);
	echo ("<table>");
	echo ("<tr>");
	echo ("<td>Username</td>");
	for ($i=0; $i<$rows; $i++) {
		echo("<td>");
		$result = mysql_query("SELECT * FROM users", $db);
		echo(mysql_result($result, $i, "username"));
		echo("</td>");
	}
	echo ("</tr>");
	echo ("<tr>");
	echo ("<td>Password</td>");
	for ($i=0; $i<$rows; $i++) {
	echo ("<td>");
		$result = mysql_query("SELECT * FROM users", $db);
		echo(mysql_result($result, $i, "password"));
	echo ("/td>");
	}
	echo ("</tr>");
	echo ("</table>");


?>
THANKYOU!

edg

Posted: Wed Aug 27, 2003 3:23 pm
by JAM
First look shows

Code: Select all

// bad
 $rows = mysql_result($result,0,);
 // better
 $rows = mysql_result($result,0); // a , to much

Posted: Wed Aug 27, 2003 3:32 pm
by edg
JAM wrote:First look shows

Code: Select all

// bad
 $rows = mysql_result($result,0,);
 // better
 $rows = mysql_result($result,0); // a , to much
*Bows down* You, sir, are truely a god amongst men.

edg

Posted: Wed Aug 27, 2003 3:45 pm
by JAM
Did it work after chaning that?
I didn't go thru the entire script in detail, so I might have missed something...

Posted: Wed Aug 27, 2003 3:51 pm
by edg
JAM wrote:Did it work after chaning that?
I didn't go thru the entire script in detail, so I might have missed something...
Yeah, printed fine. I added a mdecrypt and still good. Only problem now is I want to change i from horizontal to vertical (as I reliased horizontal would be useless with chunks of records) and I broke it somehow. Should be able to find it though.

edg

Posted: Wed Aug 27, 2003 4:23 pm
by JAM
Good to hear, just checking.

Posted: Wed Aug 27, 2003 8:00 pm
by m3mn0n
Study both manuals:

PHP Manual
MySQL Documentaion

Posted: Wed Aug 27, 2003 8:53 pm
by RFairey
Note the line number at which PHP stops parsing - that'll help you spot typing errors like extra commas and missed semicolons very quickly.

Posted: Thu Aug 28, 2003 3:24 am
by edg
RFairey wrote:Note the line number at which PHP stops parsing - that'll help you spot typing errors like extra commas and missed semicolons very quickly.
Normally I would, but I'm not sure why by my PHP is throwing up errors :-\

edg