<table border="1">

                <!-- <tr> -->

                $i = 1;

                    $result = $pager->paginate();
                    while($data = mysql_fetch_assoc($result))


                <td><a href="dashboard.php"><img src="images/<?php echo $data['newfilename']; ?>" height="150px" width="150px"><?php  
                $filename = $data['newfilename'];
                //echo $filename;

                $_SESSION['class'] = $data['class'];
                //$_SESSION['echo $filename']; ?><br><br><?php echo $data['class']; ?></a>              

                <a href="#" onclick="doSomething();">Click Me!</a>

                if($i % 5 == 0){
                echo '<br>';
                echo '<tr>';



                <?php /*
                <td><a href="#"><img src="../../images/Computer.jpg" height="150px" width="150px"><br><br>Computer Class</a></td>
                <td><a href="#"><img src="../../images/history.gif" height="150px" width="150px"><br><br>History Class</a></td>
                <td><a href="#"><img src="../../images/Math.png" height="150px" width="150px"><br><br>Math Class</a></td>              
                <td><a href="#"><img src="../../images/Social.png" height="150px" width="150px"><br><br>Social Class</a></td>
                <td><a href="#"><img src="../../images/Tutorial.jpg" height="150px" width="150px"><br><br>Tutorial</a></td>*/ ?>
                <!-- </tr> -->



I am trying to echo class and when someone click the echo class - the session that is being registered is the session that is equal to the class that being clicked, instead of the last class row in the table. How to create such program ? How to fix my program?

// the following logic only shows the last row that appears in the table
$_SESSION['class'] = $data['class'];

<br><br><?php echo $data['class']; ?>

this should be an easy thing for you to code. Have you look at jquery ajax?

What are you trying to acheieve exactly? Mixing server side sessions with onclick events usually indicates you need to rethink your logic.

Nonetheless, for your question you need a bit of JavaScript:


<a href="#" onclick="doSomething();">


<a href="#" class="clickable" data-session="something"> ...

Then, to catch the click:

$('.clickable').click(function() {
    var sessionFromLink = $(this).data("session", "default-value");
    // do other stuff here ...

Hope that helps. I think it's what you're after.

To compare the clicked link to the value stored in a session. YOu could use an ajax call. Alternatively, as long as the data is not sensitive, output the value in a javascript value:

var currentSession = '<?php echo(!empty($_SESSION['something'])) ? $_SESSION['something'] : '';' ?>'; // security checks, escape output etc.

You could then use the currentSession variable within the above click event.

However, I'd personally be looking refactor your soltuion, as things are getting rather arkward and insecure pretty quickly :)