Hi,
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

Hi,
session_start();
$query="select id,name from test";
$result=mssql_query($query);
while($row=mssql_fetch_assoc($result))
{
     $pid=$row['id'];
     $pname=$row['name'];

     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>";
}

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:

session_start();

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, networking, learning, and sharing knowledge.