<?php
$this->user_id = $_SESSION['user_id']=$user->id;
//create a database connection
mysql_connect("host","user","pass") or die("Error:".mysqlerror());
//select database
mysql_select_db("db");

?>
<html>
<body>
<link href="tab.css" rel="stylesheet" type="text/css" media="all" />
 <table id="box-table-b">
  <tr>
   <th>User ID</th>
   <th>Status</th>
   <th>I.P</th>
   <th>Offer Id</th>
  </tr>

<?php
$result = mysql_query("SELECT * FROM clicks where userId='$id'");

//return the array and loop through each row
while ($row = mysql_fetch_array($result))
{
?>
   <tr>
    <td><?php echo $row['userId'];?></td>
    <td><?php echo $row['status'];?></td>
    <td><?php echo $row['clickIp'];?></td>
    <td><?php echo $row['offerId'];?></td>
  </tr>

<?php 
} 

?>

</table>
</body>
</html>

I tried adding different session variables but there is no way I can get users id in result section. Please someone tell me what code can i add to get users id.

Recommended Answers

All 3 Replies

Your question is a bit vague, however, from the looks of the source code you posted you need to have already stored the "user_id" to $_SESSION['user_id'] elsewhere in the application. Not knowing how your system is designed I can't advise any further. Please elaborate further.

...also what is user->user->id doing? Maybe you could share the source code from that method or class. And, in your SQL query you are using $id which doesn't appear to have been instantiated anywhere. Are you expecting to use the user $this->user_id to fetch the user data from the DB? If so then is also a problem. $id needs to be set or you need to use $this->user_id (if you are in a class) otherwise this code has much more fundemental problems in the basic design of what you are trying to accomplish. It appears that this code was cut and pasted from an example that you were trying to implement.

Please clarify - Thanks

In addition, try to use mysqli or PDO since mysql extension has been deprecated since PHP 5.0.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.