stealthmode666 Posted January 12, 2009 Share Posted January 12, 2009 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. Link to comment https://forums.phpfreaks.com/topic/140581-sort-an-array-to-display-2-columns-of-data/ Share on other sites More sharing options...
Mark Baker Posted January 12, 2009 Share Posted January 12, 2009 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)" ); Link to comment https://forums.phpfreaks.com/topic/140581-sort-an-array-to-display-2-columns-of-data/#findComment-735684 Share on other sites More sharing options...
stealthmode666 Posted January 12, 2009 Author Share Posted January 12, 2009 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? Link to comment https://forums.phpfreaks.com/topic/140581-sort-an-array-to-display-2-columns-of-data/#findComment-735711 Share on other sites More sharing options...
stealthmode666 Posted January 12, 2009 Author Share Posted January 12, 2009 I suspect this will still only display a list in my email, one under the other, if so how do i get it to display the two arrays in 2 columns? Link to comment https://forums.phpfreaks.com/topic/140581-sort-an-array-to-display-2-columns-of-data/#findComment-735714 Share on other sites More sharing options...
Mark Baker Posted January 12, 2009 Share Posted January 12, 2009 Only do $fields = array(); once, at the very beginning, otherwise you're erasing everything that might already be in the array whenever you do it. Link to comment https://forums.phpfreaks.com/topic/140581-sort-an-array-to-display-2-columns-of-data/#findComment-735719 Share on other sites More sharing options...
stealthmode666 Posted January 12, 2009 Author Share Posted January 12, 2009 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)" ); ?> Link to comment https://forums.phpfreaks.com/topic/140581-sort-an-array-to-display-2-columns-of-data/#findComment-735728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.