The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Question And Answer submit
Discuss Question And Answer submit in the PHP Development forum on Dev Shed. Question And Answer submit PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 7th, 2013, 08:45 AM
|
 |
Contributing User
|
|
Join Date: Sep 2012
Posts: 148
Time spent in forums: 18 h 39 m 9 sec
Reputation Power: 1
|
|
|
Question And Answer submit
Hi! I have a page with outputs questions from a database, and the user can select an answer..
all the answers are collected in a $answers array which is sent to the next page like this
Code:
<select name="answers[]"> ... </select>
Now how can i also send the Questions array to the next page..
a hidden input field cannot hold an array that easy and if i use a while loop to create many hidden fields, they all have a different name.
Anyone that can help me out please!
thanks
|

February 7th, 2013, 08:57 AM
|
|
|
They will not have different names if you create the names in the loop as well.
PHP Code:
echo "<select name=\"questions[$i]\">...</select>";
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
|

February 7th, 2013, 09:03 AM
|
 |
Contributing User
|
|
Join Date: Sep 2012
Posts: 148
Time spent in forums: 18 h 39 m 9 sec
Reputation Power: 1
|
|
|
Hm i don't understand. The questions are echo'ed by php as plain text. But i need to send the id of the questions to the POST
|

February 7th, 2013, 09:09 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
You can include the ID in the form's post method:
Code:
<form method="POST" action="checkAnswer.php?question=<?php echo $questionId; ?>">
You can also use the session.
You can also name the questions array with the answer ID:
Code:
<select name="answers[<?php echo $questionId; ?>][]"> ... </select>
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

February 7th, 2013, 09:42 AM
|
 |
Contributing User
|
|
Join Date: Sep 2012
Posts: 148
Time spent in forums: 18 h 39 m 9 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by ManiacDan You can include the ID in the form's post method:
Code:
<form method="POST" action="checkAnswer.php?question=<?php echo $questionId; ?>">
You can also use the session.
You can also name the questions array with the answer ID:
Code:
<select name="answers[<?php echo $questionId; ?>][]"> ... </select>
|
I tried the second idea and it's just outputting the $row['vraag_id']
Code:
<select name="antwoord[ <?php echo $row['vraag_id'] ?> ] [] ">
|

February 7th, 2013, 09:51 AM
|
|
|
|
If that is the case then you probably have quotes messed up somewhere. It is treating the $row variable as a literal string. Post all your code and use [ PHP ] tags. See the sticky at the top of this forum.
|

February 7th, 2013, 09:54 AM
|
 |
Contributing User
|
|
Join Date: Sep 2012
Posts: 148
Time spent in forums: 18 h 39 m 9 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by gw1500se If that is the case then you probably have quotes messed up somewhere. It is treating the $row variable as a literal string. Post all your code and use [ PHP ] tags. See the sticky at the top of this forum. |
This is the PHP.
PHP Code:
<select name="antwoord[ <?php echo $row['vraag_id'] ?> ] [] ">
And this is how i'm trying to test-fetch it
PHP Code:
$antwoorden = $_POST['antwoord'];
print_r($antwoorden);
|

February 7th, 2013, 10:53 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
What is the resulting HTML for this PHP output?
What's the result of print_r($_POST)?
|

February 8th, 2013, 05:25 AM
|
 |
Contributing User
|
|
Join Date: Sep 2012
Posts: 148
Time spent in forums: 18 h 39 m 9 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by ManiacDan What is the resulting HTML for this PHP output?
What's the result of print_r($_POST)? |
Thanks for your help! I managed to get to this
PHP Code:
echo '<select name="antwoord['.$vraagid.'][]">';
Which results in this
Code:
Array ( [antwoord] => Array ( [135] => Array ( [0] => 6 ) [137] => Array ( [0] => 0 ) ) )
But how can i get this result to show like this
Code:
[135] => 6 [137] => 0
Thanks!
|

February 8th, 2013, 06:21 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
Hi,
by leaving out the "[]" at the end of the input name. It's useless, anyway.
|

February 8th, 2013, 06:46 AM
|
 |
Contributing User
|
|
Join Date: Sep 2012
Posts: 148
Time spent in forums: 18 h 39 m 9 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by Jacques1 Hi,
by leaving out the "[]" at the end of the input name. It's useless, anyway. |
It's fixed! Thanks a lot for the help!
Using
PHP Code:
foreach($_POST['antwoord'] as $vraag => $antwoord){ ... }
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|