PDA

View Full Version : SQL Help [+rep]



Decode
08-06-2008, 07:18 PM
SELECT * FROM user_sys WHERE USERNAME='Tom743'

If i use that on this table;

user_sys
ID USERNAME PASSWORD NAME
1 Tom743 12345password Tom
2 Bob222 54321password Bob
3 BillGates fail Bill
4 Harry password12345 Harry


i can get this;

ID USERNAME PASSWORD NAME
1 Tom743 12345password Tom

But from that is there any way to echo the NAME?

Hopefully you understand what i mean lol.

Jackboy
08-06-2008, 07:20 PM
<?
// DB CONNECTION

$g = mysql_query("SELECT * FROM `user_sys` WHERE `USERNAME`='Tom743'");
$h = mysql_fetch_assoc($g);
print $h[username];
?>


SUMMIN I SED WAS WRONG, TA SIMON


print $h[username];to



print $h[password];EDIT: Simon, im just too fast!

Invent
08-06-2008, 07:21 PM
$query = mysql_query( "SELECT * FROM `user_sys` WHERE `USERNAME` = 'Tom743'" );

$fetch = mysql_fetch_array( $query );

echo $fetch["NAME"];

Decode
08-06-2008, 07:24 PM
$query = mysql_query( "SELECT * FROM `user_sys` WHERE `USERNAME` = 'Tom743'" );

$fetch = mysql_fetch_array( $query );

echo $fetch["NAME"];






<?
// DB CONNECTION

$g = mysql_query("SELECT * FROM `user_sys` WHERE `USERNAME`='Tom743'");
$h = mysql_fetch_assoc($g);
print $h[username];
?>
You basically use mysql_fetch_assoc when selecting all of ONE rows fields, but when selecting more, for instance a member list, you use mysql_fetch_array and do a while statement.

If you wanted to display the password you would change


print $h[username];to



print $h[password];EDIT: Simon, im just too fast!
Wow thanks :) I didnt know it would be that simple. +Rep to both of you.

Pazza
08-06-2008, 08:27 PM
Wow thanks :) I didnt know it would be that simple. +Rep to both of you.
You're kidding?

Decode
08-06-2008, 08:30 PM
You're kidding?
About what?

Independent
09-06-2008, 01:53 AM
aha, even I knew this before.

(mysql_fetch_array)

Pazza
09-06-2008, 03:20 PM
About what?

It being easy :(

I cba learning w/e it is, it's too hard

Invent
09-06-2008, 06:53 PM
It being easy :(

I cba learning w/e it is, it's too hard

PHP is simple once you learn the basics.

Want to hide these adverts? Register an account for free!