Jump to content


Get user id from database


3 replies to this topic

#1 Friiks

    Young Padawan

  • Members
  • Pip
  • 56 posts
  • Gender:Male
  • Location:Latvia
  • Interests:Guitar, music, having all sorts of fun...and well enjoying my life (as enjoyable as it can be) as good as I can :D<br /><br />Oh yea, and of course - http://snowmoons.com

Posted 19 November 2006 - 11:21 AM

Well basicly problem is that I have always used while loop to get data from database and I don't know how to get only one result which should be the users id.
I did it with while loop like this
	
$result = mysql_query("select * from users");
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$_SESSION['id'] = $id;}
  $_SESSION['username'] = $username;
		$_SESSION['user_level'] = $user_level;
It registers the id in a session and the query selects a table called 'users'...but all the users get the same id number displayed now...
If this doesn't explain all I can send the full code in a pm as I don't want to post it here...

#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 19 November 2006 - 11:23 AM

simple:

$result = mysql_query("select * from users");
$r=mysql_fetch_array($result);

$id=$r["id"];
$_SESSION['id'] = $id;}
$_SESSION['username'] = $username;
$_SESSION['user_level'] = $user_level;

Matt

#3 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 20 November 2006 - 12:00 PM

View PostMr. Matt, on Nov 19 2006, 05:23 PM, said:

simple:

$result = mysql_query("select * from users");
$r=mysql_fetch_array($result);

$id=$r["id"];
$_SESSION['id'] = $id;}
$_SESSION['username'] = $username;
$_SESSION['user_level'] = $user_level;

Matt
Remember to delete the }

So it's:
$result = mysql_query("select * from users");
$r=mysql_fetch_array($result);

$id=$r["id"];
$_SESSION['id'] = $id;
$_SESSION['username'] = $username;
$_SESSION['user_level'] = $user_level;


#4 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 20 November 2006 - 12:55 PM

already helped him fix this.

Matt





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users