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