alphamoment Posted April 23, 2014 Share Posted April 23, 2014 Hello. I' have a Table in MySQL That stores data (name/email/time) of when a person last run X script.I'm trying to pull that information for each user unique to their account to display so they know that they've already ran that script todayHow it works. Run script > Create's Row storing the data > MySQL Events deletes row after 24 hours.My code to display notification if they have already ran it; $sql = 'SELECT a.name, a.time FROM timecheck a, users b WHERE a.name = b.name'; mysql_select_db('My_DB'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "Account: {$row['name']} <br> ". "Last Time Run: {$row['time']} GMT -1<br> "; } echo "It seems you have done this already today!"; ?> Now my problem is. It's displaying every row to every user. I want it to only show the user their row...What I've tried. Creating a session variable "$sessionID" $sql = 'SELECT a.name, a.time FROM timecheck a, users b WHERE a.name = b.name AND a.name=$sessionID"'; But I'm not getting any lucky. All help is appreciated, thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/287978-mysql-join-query-w-session/ Share on other sites More sharing options...
bsmither Posted April 23, 2014 Share Posted April 23, 2014 A couple of points: $sessionID is not evaluated/expanded inside single quotes. Try: AND a.name="' . $sessionID . '"'; a.name is expecting a string containing a name. So the user's name must be captured somewhere and assigned to $sessionID. Make sure $sessionID is an actual session variable. It looks like a standard variable right now. Quote Link to comment https://forums.phpfreaks.com/topic/287978-mysql-join-query-w-session/#findComment-1477133 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.