Jump to content

Retrieving database info based on user


Nothingman0

Recommended Posts

Hello, everyone.  I'm still quite new to php and mysql but I have been unable to figure this out.  I'm attempting to display a specific row and column from a mysql database based on the user.

 

 

$result = mysql_query("SELECT fbleague FROM users WHERE username = $_SESSION[username]");

 

fbleague is the column

users is the table

username is the primary key column

$_SESSION[username] is the username variable

 

Then later I try to display it with

 

echo "You are in league $result ";

 

I know $_SESSION[username] is set correctly because I can display that with no problems.  Any help would be greatly appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/41048-retrieving-database-info-based-on-user/
Share on other sites

According to the manual you only need the {} when using 2D (or more) array values such as $_SESSION['x']['y'] in a string.

 

However, I agree with GC1 and use them whenever I insert an array element in a string, or avoid the issue competely as deathstar suggests.

$result is a result set and not the selected value, you need to extract that from $result.

 

With a single value as you are selecting the easiest way is

 

$fbleague = mysql_result ($result, 0, 0);

 

which gets the first field of the first row.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.