How to store while data result set into the session variables and how retrieve the appropriate the session values of the hyperlink on test.php(on another page)... please help me out...thanks

$query="select id,name from test";

     echo "<tr>"
     echo "<td>";
    ** echo "<a href=test.php>$pid</a>";**
     echo "</td>";

     echo "<td>";
     echo "<a href=test.php>$pname</a>";
     echo "</td>";

     echo "</tr>";

Recommended Answers

All 3 Replies

You can try something like this:

   echo "<a href=test.php?varname=$_SESSION['SESSIONVARNAME']>$pname</a>";

... then access it in the test.php as:

echo $_GET['varname'];

To use session mechanism start each script with:


Store the link in the $_SESSION array from the while loop this way:

$_SESSION['link'][] = "<a href=test.php>$pid</a>";

You can also use $pid as an index for the array:

$_SESSION['link'][$pid] = "<a href=test.php>$pid</a>";

Then in the test.php page just use the array $_SESSION['link'] the way you wish.

But be aware of the server memory use. Like if you retrieve 100.000 records you will create an array with 100.000 elements in the session array which will probably be not good. In that case it is better to read the records from the database in the test.php page.

Another remark: the value for the href attribute should be in quotes so better change it like this (i used double quotes which have to be escaped):

$_SESSION['link'][] = "<a href=\"test.php\">$pid</a>";
Be a part of the DaniWeb community

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