user529649
user529649

Reputation:

PHP/MYSQL Getting only one Column Value by ID

I am new here, and i got a bit of web development skills, and because in my new project I need User information on different bits of application, I was wondering is it all right to put the whole user row in a session array or to get data each time from database if so what is the easiest way to get a column (Cell) data based on ID from MYSQL with PHP ?

Thanks

Update: to be a bit more specific like i need usertype, name , email, msgs and stuff like this.

Upvotes: 0

Views: 3491

Answers (2)

Bhanu Prakash Pandey
Bhanu Prakash Pandey

Reputation: 3785

$link = mysql_connect('localhost','root','yourPassword')
mysql_select_db('database',$link);
$sql = 'SELECT id FROM user'
$result = mysql_query($sql,$link);

$row = mysql_fetch_assoc($result);
$_SESSION['id']=$row['id'];

           // put this id in session 

Upvotes: 1

mikelbring
mikelbring

Reputation: 1492

Just put whatever you use on every page in the session, and get the other columns when you need them. Id assume the userid and username is what you would user every page.

Upvotes: 0

Related Questions