Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 2000051

Re: [PHP3] Displaying mysql_query() results From: Adam Powell (adam <email protected>)
Date: 05/05/00

Try doing it with an object, its cleaner and you can stick the results
inside text strings : ie

$res = mysql("$DB", "SELECT * FROM members WHERE username='$username'");
if ( mysql_num_rows($res) == 0 ) { echo "oops! $username doesnt exist!";
exit; }
$d = mysql_fetch_object($res);

echo "Username : $d->username<br>";
echo "Age : $d->age";

etc...

Adam

----- Original Message -----
From: "Scott S. Nicholson" <scottn <email protected>>
To: "PHP List" <php3 <email protected>>
Sent: Friday, May 05, 2000 11:51 AM
Subject: [PHP3] Displaying mysql_query() results

> I can't figure out what I'm doing wrong:
>
> <?
>
> $db = mySQL_connect(xxx, xxx, xxx);
> mysql_select_db("xxx",$db);
>
> $member_info = mysql_query("SELECT * FROM members WHERE username =
> '$username'");
> // (this returns one row, since username is unique.)
>
>
> $current_user = mysql_fetch_row($member_info);
> // It's my understanding that this returns an enumerated array, which
should
> allow me to
> // display data with "echo $current_user['fieldname'].
>
>
> $fieldname = mysql_field_name($member_info, 0);
> echo $fieldname;
> // this prints "username", so I would expect that...
>
>
> echo $current_user['username']; // this and...
> echo $current_user[0]; // ... this would print the same
> thing...
>
> ?>
>
> ...$current_user[0] works and $current_user['username'] doesn't.
>
> What am I doing wrong?
>
> Scott Nicholson
> scottn <email protected>
>
>
>
>
> --
> PHP 3 Mailing List <http://www.php.net/>
> To unsubscribe, send an empty message to php3-unsubscribe <email protected>
> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
> To search the mailing list archive, go to:
http://www.php.net/mailsearch.php3
> To contact the list administrators, e-mail: php-list-admin <email protected>
>
>

-- 
PHP 3 Mailing List <http://www.php.net/>
To unsubscribe, send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
To contact the list administrators, e-mail: php-list-admin <email protected>