Jump to content

Array Problem


inspireddesign

Recommended Posts

Hello all,

 

I think I have a simple question.  I have several arrays that I need the output from but I need the output from each array to be together.  I know WHAT?!

 

I'll try to explain:

 

I have a dynamic jQuery form that fills in a table with data.  Each "field" or <td> has separate information in each.  The way I output the data is in an input box so that I can capture the value of each.  The name attribute is the array for each input. So for example the output for each would look like this:

 

<tr>
  <td>
     <input type="text" name="fullName[]" value="input_from_user"/>
  </td>
  <td>
     <input type="text" name="Address[]" value="input_from_user"/>
  </td>
</tr>

 

If you can visualizes this we could have several rows of data from each array (fullName[] and Address[]).

 

How would I extract the data in such a way that I can clump them into their appropriate rows?  I know how to extract them one by one using foreach loop on each array but that won't do what I want.

 

I would like the output to be like this:

 

John Doe - 22 S Main Street

Jim Smith - 111 N Main Street

and so on...

 

This is what I have so far but I'm sure this isn't how to accomplish what I'm after.

 


$name			= $_POST['fullName'];
$address 			= $_POST['Address'];

$outputArry = array( "FullName" => $name, "Address" => $address );

	foreach ( $outputArry as $output ) {

		foreach ( $output as $row ) {

		  $rowFullName = $row['FullName'];		  
		  $rowAddress = $row['Address'];	
		  
		  $rowOutput .= 'Name: ' . $rowFullName . ' Address: ' . $rowAddress . '<br />';

		}

	}

         echo $rowOutput;


 

Thanks for any help on this issue.

 

Damian

 

 

Link to comment
Share on other sites

Yeah, the output is only showing the first character of the array and it's not looping correctly:

 

Here's the output:  FYI: I only have two rows of data.  So the output below in incorrect.  There should only be two rows not four. 

 

Name: D Address: D

Name: T Address: T

Name: 4 Address: 4

Name: 3 Address: 3

 

Also, I've moved the $rowOutput var in the first loop which did only give me two rows but the output was also not correct.  Here's that output:

 

Name: T DOB: T

Name: 3 DOB: 3

 

 

Damian

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.