benchew0904 Posted January 14, 2012 Share Posted January 14, 2012 hi, I want to count the total number of multiple select that user has selected instead of getting the value the user has selected How should I go about doing the counting part? <form action="1.php" method="post"> <select name="test[]" multiple="multiple"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> <option value="four">four</option> <option value="five">five</option> </select> <input type="submit" value="Send" /> </form> <?php $test=$_POST['test']; if ($test){ foreach ($test as $t){echo 'You selected ',$t,'<br />';} } ?> Link to comment https://forums.phpfreaks.com/topic/255000-count-number-of-select/ Share on other sites More sharing options...
trq Posted January 14, 2012 Share Posted January 14, 2012 count($_POST['test']); Link to comment https://forums.phpfreaks.com/topic/255000-count-number-of-select/#findComment-1307547 Share on other sites More sharing options...
laffin Posted January 14, 2012 Share Posted January 14, 2012 echo count($test) .' Item(s) selected'; Hahaha, ya beat me to punch thorpe Link to comment https://forums.phpfreaks.com/topic/255000-count-number-of-select/#findComment-1307549 Share on other sites More sharing options...
benchew0904 Posted January 14, 2012 Author Share Posted January 14, 2012 Quote echo count($test) .' Item(s) selected'; If I use the above code and if I select 3 options, it will show 3 Item(s) selected3 Item(s) selected3 Item(s) selected Link to comment https://forums.phpfreaks.com/topic/255000-count-number-of-select/#findComment-1307552 Share on other sites More sharing options...
trq Posted January 14, 2012 Share Posted January 14, 2012 Don't put it in the loop then. Link to comment https://forums.phpfreaks.com/topic/255000-count-number-of-select/#findComment-1307555 Share on other sites More sharing options...
benchew0904 Posted January 14, 2012 Author Share Posted January 14, 2012 oh okay, thanks sorry, i'm a weak in php Link to comment https://forums.phpfreaks.com/topic/255000-count-number-of-select/#findComment-1307556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.