Jump to content

Using an array and inserting ids from a mysql table until the array has 6 items


Go to solution Solved by ginerjm,

Recommended Posts

$_SESSION['numbers'] = array();
array_push($_SESSION['numbers'], $id);

So I have this code, which gives me the array:


Array ( [0] => 9 )


but what I want to do is store this, so that every time it refreshes it will keep the last time plus the new number? 

Link to comment
Share on other sites

So I'm gathering you are using your page to capture one id at a time and want to save them all, up to 6.


When you process each page submitted, add the new $id to the session var that you have created.  Check how many there are and if less than 6, repeat.


After six, I don't know what you want to do.


Do I have to write the code?

Link to comment
Share on other sites

  • Solution



So only create the array when you load the page for the first time. 


if (!isset($_SESSION['numbers']))

    $_SESSION['numbers'] = array();



Then each time you process your $_POST and add an entry, do:


if (count($_SESSION['numbers']) < 6)


   (redisplay your page and exit)


Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.