将While循环存储在数组中并将会话分配给数组

I have a search query that will fetch a record in my database

code:

while($pid_row = sqlsrv_fetch_array($stmt_pid_check))  
{ 
echo $pid_row['pid_code']; 
}

I want all the result in the while loop to be stored in an array ang assign a session variable for the array...

How can I achieve it... Please Help

Do like this

$results = array();
while($pid_row = sqlsrv_fetch_array($stmt_pid_check))  
{ 
array_push($results,$pid_row['pid_code']); 
}

$_SESSION['resultsarr']=$results;

Don't forget to add session_start(); at the begining of your PHP code.

You can now print your results from the session variable like

print_r($_SESSION['resultsarr']);

Try this,

session_start();
$results = array();
while($pid_row = sqlsrv_fetch_array($stmt_pid_check))  
{ 
$results[] = $pid_row['pid_code']; 
}

$_SESSION['resultsarr'] = $results;

To fetch all the result without using while loop.

session_start();
$results = array();
$pid_row=sqlsrv_fetch_all($stmt_pid_check);
array_push($results,$pid_row);