adamdeltoro Posted February 24, 2009 Share Posted February 24, 2009 I've already created a table "users" and another called "facts", and a login system for my website. On one page I would like to display customized data depending upon whichever member/user is logged in. Depending upon which member is logged in, there are certain values (like 1's and 0's) in their respective rows for columns called (e.g.) school_a, school_b, etc. , that I would like to have correspond to different rows in my "facts" tables that would call those rows based upon the 1's and 0's in the user's rows. How do you this? Would I need to have a session thingy going for my user, and somehow use that to then do a MySQL query on that user's data, then using the results, retrieve and print those rows under my "facts" table? Maybe some help with coding? Link to comment https://forums.phpfreaks.com/topic/146713-solved-sessions-mysql-and-php-help/ Share on other sites More sharing options...
gevans Posted February 24, 2009 Share Posted February 24, 2009 If it's only on one page you can retrieve the user's details from the db, then use them to query the db for a second time to get the relevant facts. Link to comment https://forums.phpfreaks.com/topic/146713-solved-sessions-mysql-and-php-help/#findComment-770294 Share on other sites More sharing options...
Boo-urns Posted February 24, 2009 Share Posted February 24, 2009 A combination of sessions and queries is the way to go. When logged in start a session and create session variables. I setup userID, and whatever other variables will need to be read frequently. Then on a page for your facts check the session variable and pull information from that. Link to comment https://forums.phpfreaks.com/topic/146713-solved-sessions-mysql-and-php-help/#findComment-770297 Share on other sites More sharing options...
adamdeltoro Posted February 24, 2009 Author Share Posted February 24, 2009 so when you set a session ID, you can set info that already exists from their corresponding "user" rows? If so, how would you do that? And how do you call data from the session id I set? I really appreciate your help, and could you perhaps give me an example in coding? I'm a wee-bit new to this. Link to comment https://forums.phpfreaks.com/topic/146713-solved-sessions-mysql-and-php-help/#findComment-770312 Share on other sites More sharing options...
napurist Posted February 24, 2009 Share Posted February 24, 2009 If the user successfully logs in then put something like - $_SESSION['id'] = $id; Of course the $id variable above should already be set based upon a previous SQL statement where you did something like $sql = 'SELECT id FROM users WHERE username = $_POST['username'] AND pass = $_POST['pass']'; $row = mysql_fetch_assoc(mysql_query($sql)); $id = $row['id']; Be sure to put session_start(); at the beginning of every page to assure you can write and read to the session variable. You call it at any time from any page (that has session_start() by just using $_SESSION['id']. This is very basic framework to get you started. There's a little more if you want it secure and some error control. Link to comment https://forums.phpfreaks.com/topic/146713-solved-sessions-mysql-and-php-help/#findComment-770348 Share on other sites More sharing options...
adamdeltoro Posted February 25, 2009 Author Share Posted February 25, 2009 Thanks so much for your help. Link to comment https://forums.phpfreaks.com/topic/146713-solved-sessions-mysql-and-php-help/#findComment-770777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.