Here's the scoop,
I have a survey system I am writing. I have a database with a table "questions" that contains 2 fields on with the name of the question and one with the answers (there are multiple answers for each question).
I seperate the answers by a custom tag "<znxt>" and explode the answer from the database to display it correctly.
I am at the point where I need to edit the order of the questions. I pull the answers from the database, explode it, and output a text field with a number value (the order) and then each answer in a text field beside it. Using an array I have the name of the 'reorder' field set as "reorder[1]" and accordingly the 'answer' field as "answer[1]". Now when someone changes the number in the reorder field and hits a button it sends them to a new page/script to reorder them.
I get the output I want, however, it is not in the right order... Here is what I have for the form page:
// Find the questiosn with the defined Unique ID in url
$getqquery = "SELECT * FROM questions WHERE quid = '$findq'";
$getqresult = mysql_query ($getqquery);
if (mysql_num_rows($getqresult) > 0 )
{
while ($getqr = mysql_fetch_array($getqresult))
{
$category = $getqr['category'];
$questionname = $getqr['questionname'];
$type = $getqr['type'];
$sid = $getqr['sid'];
$quid = $getqr['quid'];
echo "<b>$questionname</b> - $type<br><br>\n";
// Find the answers for this question already in database.
$pullquery = "SELECT answers FROM questions WHERE quid = '$findq' AND answers !=''";
$pullresult = mysql_query ($pullquery);
if (mysql_num_rows($pullresult) > 0 )
{
echo "<form enctype='multipart/form-data' action='$phpself' method='post'>\n";
while ($pullv = mysql_fetch_array($pullresult))
{
$pullanswers = $pullv['answers'];
$pullanswers = explode('<znxt>',$pullanswers);
$countanswers = count($pullanswers);
for ( $i = 1; $i <= $countanswers; $i++)
{
$iindex = $i-1;
echo "<div style='margin-bottom: 5px;'>\n<input name='reordervalue[$i]' type='text' value='$i' size='1'>";
echo " \n<input name='answer[$i]' type='text' value='$pullanswers[$iindex]' readonly='true'>";
echo " \n[ <a href='#'>Delete</a> ]\n</div>\n\n";
}
}
echo "<br><input type='hidden' name='quid' value='$quid'><input name='reorder' type='submit' value='Re Order'></form><br><br>\n\n";
}
echo "<form enctype='multipart/form-data' action='define_answers.php' method='post'>\n
<input type='hidden' name='quid' value='$quid'>
Insert each answer 1 at a time:<br><input name='options' type='text'>
<br>
<input type='submit' name='submit' value='Submit'>
</form><br><br><a href='view_surveys.php'>View Surveys</a>";
}
And to process it right now this is what I have:
$reordervalue = $_POST['reordervalue'];
$answer = $_POST['answer'];
for ( $i = 1; $i <= count($answer); $i++ )
{
echo "$reordervalue[$i] - $answer[$i]<br>";
}
I need to know how to display or print them in the right order starting from 1-whatever. Right now they print 3,1,2 or whatnot.
Any help is appreciated.
Thanks,
Eric T