0

I have this from my print_r

Array
(
    [jform] => Array
        (
            [itinerary] => Array
                (
                    [0] => 1
                    [1] => 2
                )

        )

)

I have some code and then this bit

    foreach($_POST as $value) {

    $extraDATA[] = $value; 

    }

    $extraDATA = implode(',',$extraDATA);


   $updatEntry="UPDATE #__tours SET itinerary='$extraDATA' WHERE id='$id'";
   $db->setQuery($updatEntry);
   $db->query();

I can not get that array to produce 1,2 so i can update the row.

Cheers in advance Jonny

5
  • 2
    It really isn't a good idea to store comma-separated data in a database; far better to normalise your table structures Commented Oct 29, 2014 at 8:19
  • its a very simple field that will hold a bunch of numbers. I have no choice over the database structure unfortunately. Commented Oct 29, 2014 at 8:21
  • @MarkBaker i don't understand why you commented unless you were willing to help? you're obviously quite intelligent but unless you are willing to link me to more information or guide me through what you mean then its kind of pointless to my question. I just have a very simple question. It will work for what i need and is completely secure. Im just stumped because everything i have tried just returns the word array. Commented Oct 29, 2014 at 8:26
  • My comment was made to try and help prevent you doing something you'll regret doing in the future, and included the keywords like "normalise" to allow you to do a simple google search.... I'm sorry I bothered now Commented Oct 29, 2014 at 8:32
  • @MarkBaker ok im sorry i commented back. I didnt me to guilt trip me. I am in no way as clued up as you and all i wanted was help with my question as i did not ask is there a better way to do this. Anyways enjoy your day/night. Commented Oct 29, 2014 at 8:37

1 Answer 1

1

Sounds like you wanna do something like:

$extraDATA = implode(',', $_POST['jform']['itinerary']);

Basically you wanna implode() the child-array that has no more children.

Sign up to request clarification or add additional context in comments.

5 Comments

Im trying this but i think i did and it did not work.I will let you know shortly.
Could you post the result for print_r($_POST) if it doesn't work, I can't guess your form-structure :)
i have updated my question with the print_r($POST) and it is slightly different yes.
Changed my answer accordingly :)
That is immensely helpful. You have taught me something. I am very much a hobby coder and not after a noble prize by far lol. Thanks heaps mate :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.