-1

dashboard.php

<table border="1">

                <tr>
                <!-- <tr> -->
                <?php 

                $i = 1;

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

                ?>


                <td></td>
                <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>
                <?php

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

                $i++;

                    }
                }
                ?>              
                </td>



                <?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>
                </tr>
                <tr>
                <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> -->


                </tr>
                </table>

Hello,

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']; ?>

3
Contributors
2
Replies
40
Views
2 Years
Discussion Span
Last Post by Web Dev Rob
0

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:

Change:

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

To:

<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 :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.