I use the PHP manual and the on-line resources/tutorials, such as PHP.net I
have lots of time to read these things, because...well...I have no life
GRIN
I just kind of stumble on these things.
-Original Message-
From: Chris MacKenzie [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 04, 2002 12:51 AM
To: Rick Emery
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Submitting Dynamic Form
Ah, I just knew there must be an easy way of doing it. Thanks Rick !
Is there a good reference on stuff like this with some examples ?
Am I pushing the friendship ? :-)
Rick Emery wrote:
$HTTP_POST_VARS or $_POST is an associative array that holds the keys and
values for all inputs/selects in form from the submitted page. Use
array_keys() to determine the names of all your list boxes to examine each
key and its value. Or you can use the list($key,$val) =
each($HTTP_POST_VARS) construct to extract each key and value.
So then you just walk through the array and process each entry.
-Original Message-
From: Chris MacKenzie [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 03, 2002 8:47 AM
To: Rick Emery
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Submitting Dynamic Form
Hi Rick,
Here's a code snippet (less error checking). Basically there could be as
many as twnety questions listed with their associated listboxes of
possible answers. Also be aware that ms-sql identity type is similar to
mysqls autoincrement type except that once a record is deleted, that
identity value is never used again.
My problem is that since the question_id field is never guaranteed to be
sequential and seeing that I have named the answer listboxes with the
question_id field, what is a good way to extract the values from the
form and perform an update query ?
How can I do this if I don't know what the question_id values will be ?
-- CUT
$sql= SELECT * FROM tbl_exam_questions ORDER BY question_id;;
$result=mssql_query($sql,$conn1);
$numrows = mssql_num_rows($result);
print 'form method=POST action=submit_exam_answers.php name=F1';
## List All Questions and load the possible answers into list box.
for($cnt = 0; $cnt $numrows; $cnt++){
$row = mssql_fetch_array($result);
print 'p'.$row[question_text].'/p';
print 'My Answer is: select size=1
name='.$row[question_id].'option selected value=0- SELECT ONE
-/option';
## Now fetch the possible answers and load it into the list box.
$pa_sql = SELECT * FROM tbl_exam_answers WHERE question_id =
.$row[question_id].;;
$pa_result = mssql_query($pa_sql,$conn1);
$pa_numrows = mssql_num_rows($pa_result);
for($pa_cnt = 0; $pa_cnt $pa_numrows; $pa_cnt++) {
$pa_row = mssql_fetch_array($pa_result);
print 'option
value='.$pa_row[id].''.$pa_row[p_answers].'/option';
}
print '/selectbrhrbr';
## Finished Loading Possible Answers into list box.
}
print 'pinput type=submit value=Save Answer name=Submitinput
type=reset value=Reset Form name=Reset/p/form';
-- CUT
Oh, and before I forget tbl_exam_questions.correct_answer holds the
relevent id entry from tbl_exam_answers
what happened when you extracted the form field names from the DB?
Hi All,
I'm pretty new to the whole php thing and I'm currently making an
multiple choice exam type of thing with php/mssql.
The two tables concerned are called tbl_exam_questions and
tbl_exam_questions which are defined like so.
[tbl_exam_questions] (
[question_id] [int] IDENTITY (1, 1) NOT NULL ,
[question_text] [varchar] (355) NOT NULL ,
[correct_answer] [int] NOT NULL
) ON [PRIMARY]
[tbl_exam_answers] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[question_id] [int] NOT NULL ,
[p_answers] [varchar] (255) NOT NULL
) ON [PRIMARY]
What I'm trying to do is to pull all the questions out and display them
with the possible answer in a html form and dropbox.
I'm displaying the entire exam on one page, with one submit button on
the bottom so that the student can review the answers before finally
submitting them.
The problem I have is that the form field names are dynamic in that
they
are set up the value held in tbl_exam_answers.question_id and with
ms-sql the identity type is not guarenteed to be incremental, so how
can
I reference them to send a query back to the DB to mark the student ?
Have I painted myself into a corner ? :-/
--
Rgds,
Chris MacKenzie
Windows: Where do you want to go today ?
Mac OS: Where do you want to be tomorrow ?
Linux: Are you coming or what ?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php