开发者

Grabbing post data from an array of selection boxes

This has been driving me crazy for the past few days. I've done something similar with check boxes and figured this would work but it didn't. I have my selection box set up like this..

while ($row = mysql_fetch_array($queryResult2))
{

echo "<table border=\"1\" \"black\" \"solid\">";
   echo "<tr><th>News item</th><td>";
   echo $row['heading'];
  echo "</td></tr>";
   echo "<tr><th>Order</th><td>";

 if( $row['id'] == 0)
 $id = "first";
 if( $row['id'] == 1)
 $id = "second";
 if( $row['id'] == 2)
 $id = "third";
 if( $row['id'] == 3)
 $id = "fourth";
 if( $row['id'] == 4)
 $id = "fith";
 if( $row['id'] == 5)
 $id = "sixth";
 if( $row['id'] == 6)
 $id = "seventh";
 if( $row['id'] == 7)
 $id = "eighth";
 if( $row['id'] == 8)
 $id = "ninth";
 if( $row['id'] == 9)
 $id = "tenth";

 echo "<select name='order[]'>
 <option value='$id'>". $id ."</option>
 <option name='first' value='1'>first</option>
 <option name='second' value='2'>second</option>
 <option name='order[]' value='3'>third</option>
 <option name='order[]' value='4'>fourth</option>
 <option name='order[]' value='5'>fith</option>
 <option name='order[]' value='6'>sixth</option>
 <option name='order[]' value='7'>seventh</option>
 <option name='order[]' value='8'>eighth</option>
 <option name='order[]' v开发者_Go百科alue='9'>ninth</option>
 <option name='order[]' value='10'>tenth</option>
 </select>";

Then it comes over to the next page like this when I do a print_r($_POST);

Array ( [order] => Array ( [0] => first [1] => second [2] => third [3] => fourth [4] => fith [5] => sixth [6] => seventh [7] => eighth [8] => ninth [9] => tenth ) )

How can I grab all of my data and put it into a variable so that I may update my database with this information?


I believe that you will want something similar to the following:

<form action="some_file.php" method="post">

 <select multiple="multiple" name="test[]">
  <option value="1">Test 1</option>
  <option value="2">Test 2</option>
  <option value="3">Test 3</option>
  <option value="4">Test 4</option>
  <option value="5">Test 5</option>
 </select>

 <input type="submit" />

</form>

You do not want name attributes on the option items. This might be messing it up for you.

What I think you should do:

  • Add multiple="multiple" to the select tag
  • Remove name attributes from the options in the select input
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜