searls03 Posted March 30, 2012 Share Posted March 30, 2012 Ok, So what I need is a way for arrays to combine. My basic structure is going to look like this for the form that needs submission: <form> <input name="name[]" /> <input name="name1[]" /> <input name="name[]" /> <input name="name1[]" /> <input name="name[]" /> <input name="name1[]" /> </form> then on the page it submits to, I need an array to form that will combine all the inputs to looks something like this: "name" "name1"; "name" "name1"; "name" "name1";.......... where the first set is the first name and name1, second is second, third is third, etc. The string of arrays will only end when there are no more left, so if there were 6, it would combine 6. how do I do something like this? Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 30, 2012 Share Posted March 30, 2012 Then just change your field names so the data will already be in the format you need. <form> <input name="names[0]['name']" /> <input name="names[0]['name1']" /> <input name="names[1]['name']" /> <input name="names[1]['name1']" /> <input name="names[2]['name']" /> <input name="names[2]['name1']" /> </form> Although it would be best to create the fields using PHP code for($i=0; $i<3; $i++) { echo "<input name=\"names[0]['name']\" />\n"; echo "<input name=\"names[0]['name1']\" />\n"; } The submitted data will be in this format Array ( [0] => Array ( [name] => name from first set [name1] => name1 from first set ) [1] => Array ( [name] => name from second set [name1] => name1 from second set ) [2] => Array ( [name] => name from third set [name1] => name1 from third set ) ) Quote Link to comment Share on other sites More sharing options...
batwimp Posted March 30, 2012 Share Posted March 30, 2012 psycho, did you mean: for($i=0; $i<3; $i++) { echo "<input name=\"names[$i]['name']\" />\n"; echo "<input name=\"names[$i]['name1']\" />\n"; } Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 31, 2012 Author Share Posted March 31, 2012 how exactly do they combine then? I am bad at writing arrays. Never have been able to, maybe someday will. anyways, could you help me with that. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 31, 2012 Share Posted March 31, 2012 psycho, did you mean: for($i=0; $i<3; $i++) { echo "<input name=\"names[$i]['name']\" />\n"; echo "<input name=\"names[$i]['name1']\" />\n"; } Yes, I did. BUt, on second review I also forgot that you don't put quotes around the index names in the HTML form, so it should actually be like this: for($i=0; $i<3; $i++) { echo "<input name=\"names[$i][name]\" />\n"; echo "<input name=\"names[$i][name1]\" />\n"; } how exactly do they combine then? I am bad at writing arrays. Never have been able to, maybe someday will. anyways, could you help me with that. Seriously? Please re-read what I said. I told you that by creating the input fields with names in that format the data would ALREADY be in the format you requested and I even provided an example of what that array would look like. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 31, 2012 Author Share Posted March 31, 2012 I don't know to read arays well so sorry. I didn't know that. To me it looks like they would be two values. Sorry bout that. Will that make it one string? The semicolons were part of the string that I wanted. Just want to make sure Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 31, 2012 Author Share Posted March 31, 2012 ok. what is going to happen is the array fields are produced through a loop. the first loop I want the 0, second the 1, 3rd the 2. etc. when I say 0,1,or 2 I mean the name[1]. how do I do this? Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 31, 2012 Author Share Posted March 31, 2012 the code is like this : <?php // Query member data from the database and ready it for display $sql4 = mysql_query("SELECT * FROM labels where item_id='".$pid."'"); while($row = mysql_fetch_array($sql4))for($i=0; $i<1; $i++){ $label =$row["label"]; $lid=$row['id']; echo $label; ?> <?php echo "<input name=\"names[$i][name1]\" value=\"$label\" />\n"; echo "<select name=\"names[$i][name]\" />\n"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.