patheticsam Posted October 9, 2013 Share Posted October 9, 2013 Hi, I'm new to php and I have a pretty basic question : I have a form that passes about 50 different fields to another page. Once on the page I get the value like this : $event10 = $_POST['event10']; $event11 = $_POST['event11']; $event12 = $_POST['event12']; $event13 = $_POST['event13']; $event14 = $_POST['event14']; $event15 = $_POST['event15']; $event16 = $_POST['event16']; $event17 = $_POST['event17']; $event18 = $_POST['event18']; $event19 = $_POST['event19']; $event20 = $_POST['event20']; $event21 = $_POST['event21']; $event22 = $_POST['event22']; $event23 = $_POST['event23']; $event24 = $_POST['event24']; $event25 = $_POST['event25']; $event26 = $_POST['event26']; $event27 = $_POST['event27']; $event28 = $_POST['event28']; $event29 = $_POST['event29']; $event30 = $_POST['event30']; $event31 = $_POST['event31']; $event32 = $_POST['event32']; $event33 = $_POST['event33']; $event34 = $_POST['event34']; $event35 = $_POST['event35']; $event36 = $_POST['event36']; $event37 = $_POST['event37']; $event38 = $_POST['event38']; $event39 = $_POST['event39']; $event40 = $_POST['event40']; $event41 = $_POST['event41']; $event42 = $_POST['event42']; $event43 = $_POST['event43']; $event44 = $_POST['event44']; $event45 = $_POST['event45']; $event46 = $_POST['event46']; $event47 = $_POST['event47']; $event48 = $_POST['event48']; $event49 = $_POST['event49']; $event50 = $_POST['event50']; $event51 = $_POST['event51']; $event52 = $_POST['event52']; $event53 = $_POST['event53']; $event54 = $_POST['event54']; Some of these variables values are left empty. Basically what I'm trying to do is to output the number of values that are NOT empty and multiply the amount by 500. If anyone can help me out or point me to a tutorial it would be really appreciated!! Thank you!! Quote Link to comment https://forums.phpfreaks.com/topic/282852-newbie-question/ Share on other sites More sharing options...
mac_gyver Posted October 9, 2013 Share Posted October 9, 2013 (edited) your first step will be to use an array name for the form field - name='event[x]' (where the x is the event number 1,2,3...) this will let you use php's array functions to operate on the data. the submitted values will be an array in $_POST['event']. to filter out the empty values, you would use array_filter(). count() would then given you a count of the remaining elements. Edited October 9, 2013 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/282852-newbie-question/#findComment-1453344 Share on other sites More sharing options...
Solution sasa Posted October 10, 2013 Solution Share Posted October 10, 2013 (edited) or $count = 0; for($i = 10; $i < 55; $i++){ if($_POST['event'.$i] != '') $count++; } echo $count * 5000; Edited October 10, 2013 by sasa Quote Link to comment https://forums.phpfreaks.com/topic/282852-newbie-question/#findComment-1453410 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.