php multiple query statements in address bar

Join Discord

Far

tsniffer
Staff member
Developer
May 19, 2003
20,198
30
2,801
540
im still cracking on with my project, at the moment im trying to get multiple page entries to work.

iv got my main page which has pages setup and working

classserver/examlist.php?page=1

and iv got my exams working (taking the correct exam questions from the first page.

classserver/onlineexam.php?id=1

but now i want to get the onlineexam.php working with multiple pages.

how do i do it so i have

classserver/onlineexam.php?id=1&page=2

what iv got so far for page numbers is...
PHP:
echo "<a href=\"OnlineExam.php?page=$prev\">Previous Page <span>I</span></a> ";
}
for($i = 1; $i <= $total_pages; $i++) 
{    if ($page == $i) 
{        echo " $i <span>I</span> ";        
}       
else
{          
echo "<a href=\"OnlineExam.php?page=$i\">$i <span>I</span></a> "; 
}
}
if ($page < $total_pages) 
{   $next = ($page + 1);
echo "<a href=\"OnlineExam.php?page=$next\"> Next Page</a>";
}

and for exam id i have...
PHP:
<?php echo "<A href='OnlineExam.php?id=$getexams3[examid]'>$getexams3[examname] </a>"		  
			?>

--------------
Sorry if its confusing, i tried to explain best i could.
 
Last edited:

KnightRider

Dedicated Member
Dedicated Member
Oct 30, 2003
107
1
65
I have done some small test on this and it seems to work,

not sure how you store your exam id so you have to add that in.

PHP:
$prev = ($page != 1 ? $page-1 : 0);
$next = ($page >= $total_pages ? 0 : $page + 1);

if ($prev != 0)
	echo "<a href='OnlineExam.php?page=$prev'>Previous Page</a> ";
	
for ($i = 1; $i <= $total_pages; $i++)
{
	//Same page number
	if ($page == $i)
	{
		echo "<span>$i</span>"; 
	} else {
		echo "<a href='OnlineExam.php?page=$i'><span>$i</span></a>";
	}
	echo " ";
}
if ($next != 0)
	echo "<a href='OnlineExam.php?page=$next'> Next Page </a> ";

Output: Previous Page 1 2 3 4 5 6 7 8 9 10 Next Page
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,198
30
2,801
540
yeah i can get the pages to work fine, but i had trouble getting both pages, and id's working in the same protocol.

i finally did it by

PHP:
<a href='OnlineExam.php?page=$i&id=$id'><span>$i</span></a>";

which works fine now.

my problem now is...

when i query the examquestions, i order tham by random (since the questions need to be in a different order for every person using it)

but when i change the page, it re randomises it, and so i get the same question on page 1 as i do page 2.

how do i stop this? so it only randomises it once, then keeps in that order.


thanks for your help.
 

KnightRider

Dedicated Member
Dedicated Member
Oct 30, 2003
107
1
65
maybe store the question ID inside an array and when the questions get loaded.

check the array to see if they had that question if so pick a differnet one,

also

how are you storing there answers?
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,198
30
2,801
540
everything is stored in a mysql database.

the answers will eventually be a 4 choice box, which is then store in the database too.

i havnt got that far yet, that will be my next step.
 

KnightRider

Dedicated Member
Dedicated Member
Oct 30, 2003
107
1
65
ok well there 3 options:

1.
Store the questions inside the sql which one it picked on page 1 page 2 etc and do a simple check when displaying the next 5 or so.

2.
Store the question id inside a array and check that but not too sure how you pass the array on to the next page.

3.
Store the question id inside a session, so it look like this $_SESSION['examQuestionID'] = '1,5,3,9';
this can be handle on any pages etc.

and do a explode on , to turn into a array and use in_array

Exmaple:
PHP:
$_SESSION['examIDList'] = '1,8,9,1';
$nextQuestionCheck = explode(',',$_SESSION['examIDList']);

$i = false;
while ($i == true) {
$randNumber = rand($min,$max);
if (!in_array($randNumber,$nextQuestionCheck )
  $i = true;
  $nextExamID = $randNumber;
}

hope this helps
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,198
30
2,801
540
i cant option 1, as more than one person (up to about 200) will be taking the exam at once, so wld be difficult to record every page ordered displayed at once i think.

option 3 sounds best.

im not that clued up on php yet unfortunately. Why have you got the '1,8,9,1' already listed in the session? i presume they are the question numbers. Since the questions are ordered randomly, how would i store the displayed questions of one page in a session? there will be 5 questions on each page.

the questions are known in the database by QuestionID, and are also linked to ExamID.

so in the database id have examID 1, which holds QuestionID 2, 5, 6, 11, 12 for example.

thanks for pointing me in the right direction.
 

KnightRider

Dedicated Member
Dedicated Member
Oct 30, 2003
107
1
65
Yes they was the question numbers as i was not sure how you store the question etc.

when the page gets built by the php just add the examID or questionID to the session some think like this:

PHP:
if (isset($_SESSION['examID'])
   $_SESSION['examID'] .= ',' . (int)$examID;
else
  $_SESSION['examID'] = (int)$examID;

(int) => to make sure stores a number and not as a string

If you like anymore help just pm
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,198
30
2,801
540
im trying to get radio buttons to save their states when i change pages (so i can go back and forth and it still show the chosen option)

but nothing im trying is working.

this is what ive got so far but it doesnt work at all, i think im going in the wrong direction tbh.

PHP:
<table width="733" id="board-spotlist">

	<?php
	if(isset($_SESSION['SESS_AnswerA']))
		{
		$AnswerA[$getexamquestion3['QuestionID']] = 'checked';
		}
	elseif(isset($_SESSION['SESS_AnswerB']))
		{
		$AnswerB[$getexamquestion3['QuestionID']] = 'checked';
		}
	elseif(isset($_SESSION['SESS_AnswerC']))
		{
		$AnswerC[$getexamquestion3['QuestionID']] = 'checked';
		}
	elseif(isset($_SESSION['SESS_AnswerD']))
		{
		$AnswerD[$getexamquestion3['QuestionID']] = 'checked';
		}
	?>
 
	<tr>
		<?php echo "<td class='title'><Input type = 'Radio' Name =".$getexamquestion3['QuestionID']. "value= '$AnswerA'></td>"
			?>
		<?php echo "<td><strong>A. </strong>".$getexamquestion3['ExamAnswerA']."</td>";
			?>
        </tr>
 
	<tr>
		<?php echo "<td class='title'><Input type = 'Radio' Name =".$getexamquestion3['QuestionID']. "value= '$AnswerB'></td>"
			?>

		<?php echo "<td><strong>B. </strong>".$getexamquestion3['ExamAnswerB']."</td>";
			?>
	</tr>

	<tr>
		<?php echo "<td class='title'><Input type = 'Radio' Name =".$getexamquestion3['QuestionID']. "value= '$AnswerC'></td>"
			?>

		<?php echo "<td><strong>C. </strong>".$getexamquestion3['ExamAnswerC']."</td>";
			?>
	</tr>

	<tr>
		<?php echo "<td class='title'><Input type = 'Radio' Name =".$getexamquestion3['QuestionID']. "value= '$AnswerD'></td>"
			?>

		<?php echo "<td><strong>D. </strong>".$getexamquestion3['ExamAnswerD']."</td>";
			?>
	</tr>


	<?php
	if($AnswerA[$getexamquestion3['QuestionID']] = 'checked')
	{
		$_SESSION['SESS_AnswerA'] = $AnswerA[$getexamquestion3['QuestionID']];		
 	}
	elseif($AnswerA[$getexamquestion3['QuestionID']] = 'checked')
	{
		$_SESSION['SESS_AnswerB'] = $AnswerB[$getexamquestion3['QuestionID']];		
 	}
	elseif($AnswerA[$getexamquestion3['QuestionID']] = 'checked')
	{
		$_SESSION['SESS_AnswerC'] = $AnswerC[$getexamquestion3['QuestionID']];		
 	}
	elseif($AnswerA[$getexamquestion3['QuestionID']] = 'checked')
	{
		$_SESSION['SESS_AnswerD'] = $AnswerD[$getexamquestion3['QuestionID']];		
 	}
	?>


	<tr>
   		<td colspan="2" class="board-line-end"></td>
	</tr>

ive posted in 4 other forums, but no ones seems to be able to help. any idea how to get it working?