Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
CodyG
Life Cycles Becoming CPU Cycles



Joined: Jan 02, 2003
Posts: 714
Location: Vancouver Island

PostPosted: Thu Jan 11, 2007 9:05 pm Reply with quote

I've been working on a chemistry practice module for a chemistry teacher friend of mine. I've finished the first go round of 9 exercises with 25 questions each and it all works great.

But I'd like to add something, after the student completes the last question ($pqnum = there are no more rows) they get page that they input their name and then submit and then the page outputs their name in the middle of a completion certificate.

In other words,
something like
if there are no more rows
header (Location: "finished.php)

I have the code for the finished form and it works, now I'm trying to find the place for it in the main code. I think it should go in the following function, but not sure, and not sure exactly how.

Any ideas?




Code:
function check($pqnum){

  $query  = "SELECT  pos_sub, neg_sub FROM chem_formulas1 WHERE qnum=$pqnum";
  $qresult = mysql_query($query) or die("Invalid query: $query") ;
  $row = mysql_fetch_array($qresult) or die("You are done... no more questions"); //just for testing gb
  $pos_sub  = $row['pos_sub'];
  $neg_sub  = $row['neg_sub'];
  if (($_POST['pos_try']<>$pos_sub)
  || ($_POST['neg_try']<>$neg_sub)) {
      return FALSE;
    }
    else {
      return TRUE;
    }
}

if (!isset($_POST['qnum'])){
  $pqnum=1;
}
else {
  $pqnum=$_POST['qnum'];
}

if (isset($_POST['submit'])){
 if (check($pqnum)){
 echo "$randimg Good Work!";
  $pqnum++;
} else {
  echo "<img src=\"images/question.gif\" alt=\"Try Again!\" title=\"Try Again!\"></img> Wrong... try again";
}}

show_form($pqnum);

_________________
"We want to see if life is ubiquitous." D.Goldin 
View user's profile Send private message
gotcha
Regular
Regular



Joined: Mar 14, 2005
Posts: 91

PostPosted: Fri Jan 12, 2007 1:21 pm Reply with quote

Maybe you can use this

Code:


$query = "SELECT MAX(qnum) as last_question FROM chem_formulas1";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

$last_question = $row['last_question'];
 
View user's profile Send private message Visit poster's website
CodyG







PostPosted: Mon Jan 15, 2007 8:38 am Reply with quote

I've finished the project.
And solved the above problem with this snippet from the function that displays the question form.

Code:




function show_form($pqnum){
  $query  = "SELECT qnum, reactant, pos, pos_sub, neg, neg_sub FROM chem_formulas1 WHERE qnum=$pqnum";
  $qresult = mysql_query($query) or die("Invalid query: $query") ;
//was:
//  $row = mysql_fetch_array($qresult) or die("  You are done... no more questions. ");
//changed to
    $row = mysql_fetch_array($qresult) or header("Location: finished1.php");


 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©