//Returns 10 question from questions table
$result = mysqli_query($con,"SELECT question FROM questions ORDER BY rand() LIMIT 10' ");
while($row = mysqli_fetch_row($result))
{
$que[]=$row[0];
}
Now I need to store this whole set of $que[]
in a session variable. (i.e 10 questions)
Something like this
$_SESSION['question'] = $que[];
$my_array[] = $_SESSION['question'];
so that $my_array[0]
returns first question, $my_array[1]
returns second questions and like that.
(Thanx for the help in advance)
Saving arrays to localStorage and sessionStorage In this example, we have an array with numbers: var ourArray =[1,2,3,4,5]; We can now save it to localStorage or sessionStorage using the setItem() method: localStorage.
Starting a PHP SessionSession variables are stored in associative array called $_SESSION[]. These variables can be accessed during lifetime of a session. The following example starts a session then register a variable called counter that is incremented each time the page is visited during the session.
Yes, You can save the class objects/instance in session and access at other pages.
session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie. When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers.
Assign
$_SESSION['question'] = $que;
print_r($_SESSION['question'][0]);
will give you first question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With