The threading is messed up on this message, so sorry for the top post.

Actually, the method that Shaunak gave is the best method to use. If you took your questions and had them formatted from this:

> <p>What color are you eyes?<br>
> <blockquote>
>    <input type=radio name=9 value=5>Blue<br>
>    <input type=radio name=9 value=7>Green<br>
> </blockquote></p>

to this:

<p>What color are you eyes?<br>
<blockquote>
        <input type=radio name=q[9] value=5>Blue<br>
        <input type=radio name=q[9] value=7>Green<br>
</blockquote></p>

You now have all of your questionIDs and answerIDs in the $_POST['q'] array.

foreach($_POST['q'] as $questionID => $answerID)
{
$query = "INSERT INTO answers (questionID, answerID) VALUES ('$questionID','$answerID');
}


Throw in some validation, of course, and then you're done. How much easier can it be?

This is what I do in my survey system. You can see a demo at http://sepodati.realxl.net/ The admin password is just password.

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals – www.phparch.com

Joe Harman wrote:

Actually... That didn't work... The QuestionID and AnswerID are
different from poll to poll.... Can I do something like a loop and pass
the QuestionID and AnswerID into other variables...

Ex. Here is my HTML that is dynamically created....
*****************************
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="play.php" method="post" name="Poll" id="Poll">
<p>The Cool Joe Survey</p>
<p>What color are you eyes?<br>
<blockquote>
        <input type=radio name=9 value=5>Blue<br>
        <input type=radio name=9 value=7>Green<br>
</blockquote></p>
<p>What Letter does your name start with<br>
<blockquote>
        <input type=radio name=14 value=19>a<br>
        <input type=radio name=14 value=20>b<br>
        <input type=radio name=14 value=21>c<br>
</blockquote></p>
<p>What Day is it<br><blockquote>
        <input type=radio name=13 value=17>Thurs<br>
        <input type=radio name=13 value=18>Fri<br>
        <input type=radio name=13 value=16>Tues<br>
</blockquote></p>
  <p align="center">
        <input name="GoForm" type="hidden" id="GoForm" value="1">
        <input type="submit" name="Submit" value="Submit Survey">
</p>
</form>
</body>
</html>

Can I do something like this on the nest page
*****************************

1 Start the do statement til radio button name equals null
2 extract (from $_POST) the radio button name and plug it into
$RadioName
3 extract (from $_POST) the radio button value and plug it into
$RadioValue
4 insert it into a MySQL table
5 while statement sends you back to 1
        * not exactly sure how I am going to do the while part

LOL

Thanks,
Joe

-----Original Message-----
From: Shaunak Kashyap [mailto:[EMAIL PROTECTED] Sent: Friday, July 25, 2003 1:14 AM
To: Joe Harman
Subject: Re: help with explode.....




The name of the set of radio buttons is the QuestionID (so it's a number)... And the options are the AnswerID (they are also numbers)...


In that case, I assume your code looks something like this:


<input type="radio" name="<?=$QuestionID?>">...

How about using an array instead of just the QuestionID as shown below:

<input type="radio" name="Question[<?=$QuestionID?>">...

That way, on the next page (the one to which this form is being
submitted) you can get the AnswerIDs by simply looping through the
$_POST["Question"] array (assuming your form submission method is post).

Hope that made sense.

Shaunak





-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to