MySQL n00b seeks help!

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
edg
Forum Newbie
Posts: 11
Joined: Wed Aug 28, 2002 12:58 pm

MySQL n00b seeks help!

Post 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
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

First look shows

Code: Select all

// bad
 $rows = mysql_result($result,0,);
 // better
 $rows = mysql_result($result,0); // a , to much
edg
Forum Newbie
Posts: 11
Joined: Wed Aug 28, 2002 12:58 pm

Post 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
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Did it work after chaning that?
I didn't go thru the entire script in detail, so I might have missed something...
edg
Forum Newbie
Posts: 11
Joined: Wed Aug 28, 2002 12:58 pm

Post 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
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Good to hear, just checking.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Study both manuals:

PHP Manual
MySQL Documentaion
RFairey
Forum Commoner
Posts: 52
Joined: Fri Jun 06, 2003 5:23 pm

Post 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.
edg
Forum Newbie
Posts: 11
Joined: Wed Aug 28, 2002 12:58 pm

Post 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
Post Reply