Jump to content

Newbie question


patheticsam
Go to solution Solved by sasa,

Recommended Posts

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!!

Link to comment
Share on other sites

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 by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.