1,105,332 Community Members

suggestions please

Member Avatar
Venter
Light Poster
25 posts since Oct 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i'm doing online quizz project.
so i'm fetching questioins & answers Randomly from database.
when ever press referesh button/f5 the questions are changing.
wat i require is when the session starts once.the questions could not be change even doing refresh..
thank u all.
eagerly waiting for ur help

Member Avatar
pritaeas
mod_pritaeas
11,298 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,833 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
1
 

Store your selected questions/answers in a session variable, once you've selected them.

Member Avatar
varma51
Newbie Poster
19 posts since Jul 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 
<?php
$query="SELECT * FROM test  ORDER BY RAND() limit 5  ";
$result=mysql_query($query)or die("cannot select DB");
$num=mysql_numrows($result);
?>

<form name="myform" id="myform" action='test.php' method='POST' href="javascript: calculate_time()">
<table>
<tr><td style='overfolw-hidden;width:400px;'> Question: </td>
<td style='overfolw-hidden;width:40px;'> OPTION A </td>
<td style='overfolw-hidden;width:40px;'> OPTION B </td>
<td style='overfolw-hidden;width:40px;'> OPTION C </td>
<td style='overfolw-hidden;width:40px;'> OPTION D </td>
</tr>

<?
while($row = mysql_fetch_array($result))
  {

echo"<tr>";
echo "<td> $row[question]</td>";
echo "<td>$row[a]<input type='radio' name='$row[qid]' value='a'> </td>";
echo "<td>$row[b]<input type='radio' name='$row[qid]' value='b'> </td>";
echo "<td>$row[c]<input type='radio' name='$row[qid]' value='c'> </td>";
echo "<td>$row[d]<input type='radio' name='$row[qid]' value='d'> </td>";
echo"</tr>";




}
?>
<tr><td></td><td><input type='submit' value='submit'></tr>
</table> <br/>

</form>

</div>

Quoted Text Here

hi this is the way i'm fetching data from database.can u please guide me ho can i store these varaiables in seesions & how to display .

Member Avatar
gon1387
Posting Whiz in Training
242 posts since Jan 2011
Reputation Points: 22 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 4 [?]
 
0
 

you can use session like this

<?php
session_start(); 
// make sure to start with this, or else 
// php won't reload the $_SESSION with the previous data

$myTest = 6;
$_SESSION["myTest"] = $myTest;

//Retrieving Data from the previous session
if(isset($_SESSION["myTest"])&&!empty($_SESSION["myTest"])){
    $myTest = $_SESSION["myTest"];
} else { // Storing Information for the next session
    $myTest = 6;
    $_SESSION["myTest"] = $myTest;
}

Let me know if that makes clear.

Member Avatar
gon1387
Posting Whiz in Training
242 posts since Jan 2011
Reputation Points: 22 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 4 [?]
 
0
 

Man, I just noticed now, I'm confused. is varma51, venter? LOL Anyhow, just let me know if you have additional queries. :D

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article