Jump to content

PHP Passing 2D Arrays to CVS


theodore_steiner

Recommended Posts

I am very, very new to php and require assistance.

I have built a multipage form. Most of the inputs on this form can be dynamically created by the user.

Here is a working example of this on codepen

When the data from the multiDimensional array is passed to the csv sheet I would like to arrange it in the following way: Array ( [0] => Position [1] => Unit [2] => Unit President ),

That way, if the user adds two or three inputs dynamically, it will be easier to see each entry.

So far I've only been able to filter the array like this:

$unitLevelPosition = $_POST["unitLevelPosition"];    $unitLevelPositionValues = "";    foreach( $unitLevelPosition as $unitPositionValue)    {        $educationHistoryValues .= $unitPositionValue;    }

The array variable is then added to the rest of the variables being printed to the cvs like this:

$csvdata = $firstName . ", " . $lastName . ", " . $educationHistoryValues; Is what I'm after even possible? And if so, can someone help me get started?

Link to comment
Share on other sites

I see you're still doing the thing I told you to stop doing...

 

Name your original HTML inputs like "input[0][0]" for the position, "input[0][1]" for the unit name, and "input[0][2]" for the president. In your Javascript, make it generate the same sort of thing except keep a counter that starts at 1 and increments every time a new row gets added. The first one added will have input[1][...], the second input[2][...], and so on. If someone removes one the "hole" at that index is not a problem.

Then take a look at what's in $_POST.

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.