Jump to content

sort an array to display 2 columns of data


stealthmode666

Recommended Posts

How do i write my script to be able to sort an array in php to display the data it sends into two columns in the email instead of one column?

$fields = array(); 
$fields{"Member_Name"} = "Members Name";
$fields{"telephone"} = "Members Contact Phone Number"; 
$fields{"Email"} = "Members Email Address";
$fields{"title"} = "Main Applicants Title";
$fields{"surname"} = "Applicants Surname"; 
$fields{"forename"} = "Forename(s)";

$fields{"Member_Name1"} = "Members Name";
$fields{"telephone1"} = "Members Contact Phone Number"; 
$fields{"Email1"} = "Members Email Address";
$fields{"title1"} = "Main Applicants Title";
$fields{"surname1"} = "Applicants Surname"; 
$fields{"forename1"} = "Forename(s)";

$body = ".......com:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

 

The above code shows two sets of data taken from a form in one array, any help with how to script this would be appreciated.

How do i write my script to be able to sort an array in php to display the data it sends into two columns in the email instead of one column?

Structure your array sensibly to start with:

$fields = array(); 
$fields[] = array("Member_Name" => "Members Name",
                      "telephone" => "Members Contact Phone Number",
                      "Email" => "Members Email Address",
                      "title" => "Main Applicants Title",
                      "surname" => "Applicants Surname",
                      "forename" => "Forename(s)"
                     );

 

 

Okay, looks a better way to do this and easier to see, many ways i know in php but books are limited and trying to do my best with little knowledge.

$fields = array(); 
$fields[] = array("Member_Name" => "Members Name",
                      "telephone" => "Members Contact Phone Number",
                      "Email" => "Members Email Address",
                      "title" => "Main Applicants Title",
                      "surname" => "Applicants Surname",
                      "forename" => "Forename(s)"
                     );

$fields = array(); 
$fields[] = array("Member_Name1" => "Members Name",
                      "telephone1" => "Members Contact Phone Number",
                      "Emai1l" => "Members Email Address",
                      "title1" => "Joint Applicants Title",
                      "surname1" => "Applicants Surname",
                      "forename1" => "Forename(s)"
                     );

 

Like this?

thanks for that, do you mean like this?

<?php
$fields = array(); 
$fields[] = array("Member_Name" => "Members Name",
                      "telephone" => "Members Contact Phone Number",
                      "Email" => "Members Email Address",
                      "title" => "Main Applicants Title",
                      "surname" => "Applicants Surname",
                      "forename" => "Forename(s)"
                     );


$fields[] = array("Member_Name1" => "Members Name",
                      "telephone1" => "Members Contact Phone Number",
                      "Emai1l" => "Members Email Address",
                      "title1" => "Joint Applicants Title",
                      "surname1" => "Joint Applicants Surname",
                      "forename1" => "Forename(s)"
                     );
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.