Jump to content

bern1o

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bern1o's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok, I've just realised the problem and feel like a total idiot. It was populating each array with the same data because I used the count variable when I should have been using the *counter* variable when iterating through the loop! Thanks for the replys though!
  2. Do you mean somehow put these values together into an array before the form is submitted? Would this be done using javascript?
  3. Yes but in that example, it seems you have hard coded 3 sets of items. If you don't know how many sets of items you will be presented with, how do you deal with that?
  4. For example, the html form will have a varying number of categories. Eg. a user will decide on having 2 categories. They will be displayed with a form consisting of 2 boxes that allows them to enter the details of their category. Category 1 amount_0 = 50 title_0 = "TestCategory 1" desc_0 = "Test Description 1" Category 2 amount_1 = 300 title_1 = "TestCategory 2" desc_1 = "Test Description 2" From this example I would like 2 arrays created. Categoryarr1 and Categoryarr2. They should have the following data: Categoryarr1[0] = 50 Categoryarr1[1] = "TestCategory 1" Categoryarr1[2] = "Test Description 1" Categoryarr2[0] = 300 Categoryarr2[1] = "TestCategory 2" Categoryarr2[2] = "Test Description 2" Does that help?
  5. Hi, This problem has been driving me crazy all day. I am relatively new to PHP. I basically am trying to populate a database with data from site users. I am using session variables to store their data temporarily as they navigate through the sign up process. A user will input how many 'categories' they wish to populate on page 1. Page 2 will then ask them to specify the details of each category. Eg Category 1: Title, Description, Amount. Category 2: Title, etc. So far I have been able to do this, I now want to store what they have input in session variables. My thoughts were to take the number of categories they have sepcified and create that number of arrays using a loop. Each array will store the details on each category. My code is as follows: $count=$_POST['count']; //Get how many categories were added //Create an array for each category for ( $counter = 0; $counter <= $count; $counter++){ ${'Categoryarr'.$counter} = array(); }; for ( $counter = 0; $counter <= $count; $counter++){ $Categoryarr[$counter][1]=$_POST['amount_'.$count]; $Categoryarr[$counter][2]=$_POST['desc_'.$count]; $Categoryarr[$counter][3]=$_POST['title_'.$count]; }; When I output the code, I seems to have created the specified number of arrays, but has populated all of them with the same data from the last category. Does anyone know where I am going wrong? Thanks, Bernard
×
×
  • 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.