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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.