Jump to content

[SOLVED] array help


adam291086

Recommended Posts

i have this array

Array

(

    [username] => l

    [password] => h

    [title] =>

    [forename1] => kjhkjh

    [forename2] => kjhk

    [surname] => kjhkjhkjh

    [addressLine1] =>

    [addressLine2] =>

    [town] =>

    [postcode] =>

    [secondEmail] =>

    [personalUrl] =>

    [postcodeStart] =>

    [authorityToWorkStatement] =>

    [contactPreference] => Mobile

    [EducationLevels_idEducationLevel] =>

    [noOfGcses] => 000

    [gcseEnglishGrade] =>

    [gcseMathsGrade] =>

    [noOfAlevels] => 0000

    [ucasPoints] => 0000

    [studentStatus] => Full-time

    [mobile] =>

    [landline] =>

    [dob] => Array

        (

            [MONTH] =>

            [DAY] =>

            [YEAR] =>

        )

 

    [penaltyPoints] =>

)

 

i need to take dob array and join the month, day and year values and join them together yyyy/mm/dd and put it back into the array for example

Array

(

    [username] => l

    [password] => h

    [title] =>

    [forename1] => kjhkjh

    [forename2] => kjhk

    [surname] => kjhkjhkjh

    [addressLine1] =>

    [addressLine2] =>

    [town] =>

    [postcode] =>

    [secondEmail] =>

    [personalUrl] =>

    [postcodeStart] =>

    [authorityToWorkStatement] =>

    [contactPreference] => Mobile

    [EducationLevels_idEducationLevel] =>

    [noOfGcses] => 000

    [gcseEnglishGrade] =>

    [gcseMathsGrade] =>

    [noOfAlevels] => 0000

    [ucasPoints] => 0000

    [studentStatus] => Full-time

    [mobile] =>

    [landline] =>

    [dob] => 2000/10/27

 

    [penaltyPoints] =>

)

 

i have no idea how to go about this can some push me in the right direction

 

 

Link to comment
https://forums.phpfreaks.com/topic/148916-solved-array-help/
Share on other sites

Hi

 

Can you not just (assuming the array is called $fred):-

 

$fred['dob'] = $fred['dob']['YEAR']."/".$fred['dob']['MONTH']."/".$fred['dob']['DAY'];

 

Although would be tempted to avoid doing that to the $_POST array (ie, copy the bits of that array elsewhere to play with).

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/148916-solved-array-help/#findComment-781952
Share on other sites

Well this is a uni project and we need to make it so that anyone can add fields into that database and the forms will automaticalyy up date.

 

so i am using this function to generate an insert query

 

function mysql_insert_array($table, $data)
        {

            foreach ($data as $field=>$value)
            {

                $fields[] = sprintf("`%s`", $value);
            }
            $field_list = join(',', $fields);

            $query = sprintf("INSERT INTO `%s` VALUES %s ", $table, $field_list);

            return $query;
        }

hence the reason i use $_POST array so that all the form info will update automatically as the input field names ect = the names within the database table.

Link to comment
https://forums.phpfreaks.com/topic/148916-solved-array-help/#findComment-781955
Share on other sites

i solved it by doing

 

$date = $_POST['dob']['YEAR']."-".$_POST['dob']['MONTH']."-".$_POST['dob']['DAY'];
$test = array();

foreach ($_POST as $key => $value)
{
    if ($key == 'dob')
    {
        $test[$key] = $date;
        continue;
    }
    else
    {
        $test[$key] = $value;
    }
}

Link to comment
https://forums.phpfreaks.com/topic/148916-solved-array-help/#findComment-781975
Share on other sites

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.