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 />';} } ?> Quote 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']); Quote 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 Quote 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 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 Quote 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. Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/255000-count-number-of-select/#findComment-1307556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.