Jump to content

MySQL Join Query w/ Session


alphamoment

Recommended Posts

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 today

How 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.

Link to comment
https://forums.phpfreaks.com/topic/287978-mysql-join-query-w-session/
Share on other sites

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.

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.