SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Database store in array] Help make the order change, from the front to be the end

    Hi guys,

    1. i have a database field stored in array, the default is like this

    a:3:{i:0;a:5:{i:3;s:7:"4683203";i:6;s:7:"4683204";i:9;s:7:"4768795";i:10;s:7:"4683206";i:11;s:7:"4925120";}i:1;a:4:{i:0;s:7:"4683208";i:2;s:7:"4683212";i:3;s:7:"4683211";i:4;s:7:"4925121";}i:2;a:0:{}}


    2. now i want to add a value in that field, by run this link : http://www.domain.com/filename.php?cmd=addmod&modid=2 (please see the complete filename.php file content here : http://pastebin.com/BabtP21Y , the part that i think responsible for this i think about line 674-709, that i highlighted there)

    the field become like this, there is new code in the front that highlighted below

    a:3:{i:0;a:5:{i:3;s:7:"4683203";i:6;s:7:"4683204";i:9;s:7:"4768795";i:10;s:7:"4683206";i:11;s:7:"4925120";}i:1;a:5:{i:0;i:4924131;i:1;s:7:"4683208";i:2;s:7:"4683212";i:3;s:7:"4683211";i:4;s:7:"4925121";}i:2;a:0:{}}




    3. the only problem, i need it to put it in the back and the position are reserved, so like this that highlighted below
    a:3:{i:0;a:5:{i:3;s:7:"4683203";i:6;s:7:"4683204";i:9;s:7:"4768795";i:10;s:7:"4683206";i:11;s:7:"4925120";}i:1;a:5:{i:0;s:7:"4683208";i:2;s:7:"4683212";i:3;s:7:"4683211";i:4;s:7:"4925121";i:1;i:4924131;}i:2;a:0:{}}
    please help to make the array position stored like that, maybe by editing the php file





    GBU for that helping
    Make the world better

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Okay your pastebin link isnt working. So flying blind a bit on what the code is actually doing...

    Unserializing the array results in a bit more readable format:
    Code:
    Array
    (
        [0] => Array
            (
                [3] => 4683203
                [6] => 4683204
                [9] => 4768795
                [10] => 4683206
                [11] => 4925120
            )
    
        [1] => Array
            (
                [0] => 4924131
                [1] => 4683208
                [2] => 4683212
                [3] => 4683211
                [4] => 4925121
            )
    
        [2] => Array
            (
            )
    
    )
    So array_push the value returned by array_shift'ing the array element at key 1.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •