Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-10-2002, 02:28 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
submitting arrays

I have an array that i need to submit to the next page.

<form method=post action=test.php>

<input type=hidden name=questionArray[] value=$ob->questionArray>

<input type=submit value=\"Start Test >>\">

</form>

on the next page, .. when i print $questionArray[0] , it just returns the word "Array"

i've done this many times before, i can't figure out why it isn't working.

and btw.. $ob->questionArray is a valid array. on the same page of this form, i am looping the array and printing the results.
sde is offline   Reply With Quote
Old 09-10-2002, 02:34 PM   #2 (permalink)
sdeming
Code Monkey
 
Join Date: Jul 2002
Location: Michigan
Posts: 85
sdeming is on a distinguished road
I believe that the above code is setting the first element of questionArray to the array $ob->questionArray.

I'm pretty sure you have to set each element specifically:
Code:
<input type=hidden name=questionArray[0] value=$ob->questionArray[0]>
<input type=hidden name=questionArray[1] value=$ob->questionArray[1]>
etc. You could pretty easily build a foreach loop that did this for you.
__________________
Scott
B4 09 BA 09 01 CD 21 CD 20 53 63 6F 74 74 24
sdeming is offline   Reply With Quote
Old 09-10-2002, 02:41 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
thanks scott .. i thought there was another way... i guess it is just when you are generating an array inside the form itself.. kinda like a select field.

anyhow, here is the code that worked:
Code:
 
$i=0;		
foreach($ob->questionArray as $each)
{
  echo "<input type=hidden name=questionArray[$i] value=$each>";
  $i++;
}
sde is offline   Reply With Quote
Old 09-10-2002, 04:08 PM   #4 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
$ob->questionArray is a reference to an array right? probably when you print it out:
Code:
echo $ob->questionArray
you will also get "Array"... maybe there is a way of sending its actually refence value, much like in c++ or java, and then constructing a new array from this value.. but I don't think php would allow that level of access to the memory and im not even sure if the memory would hang around once the page has been left (probably loses scope) maybe try setting a global variable somewhere (like the application or session objects in ASP) and then trying the memory stuff

however that is probably way to complicated to bother with.
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 09-10-2002, 05:08 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
yes abc, you are right. echo $ob->questionArray would print "array" , however echo $ob->questionArray[0] would print my first test question id.

<input type=hidden name=questionArray[] value=$ob->questionArray> " ... now when i send this in a form, one might think that "$questionArray[0]" would print out the first test question also on the page it was submiited to, .. but it did not. it printed "Array".

i am familiar with how you would manipulate arrays in c++ by pointers, however php executes once and generates your page. after your page is generated, your program is done. you rely on your browser for any type of variables. you don't have the luxory of keeping your program running in between pages.

well, .. if you count sessions, but that is not the same. sessions are definately an alternative. i could register the array in a session, but i didn't want to do that. i was hoping i could simple pass an array through a form using a hidden field without a loop.

the loop works fine though.

thanks for the input !
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
combining arrays Engineer Standard C, C++ 11 03-12-2005 10:23 AM
Dynamic Arrays, the 'right' way. Mr.Anderson Standard C, C++ 10 10-05-2004 06:00 AM
need help with arrays CoW Standard C, C++ 12 11-04-2003 10:09 AM
sort arrays Apodysophilia Java 9 04-04-2003 06:18 AM


All times are GMT -8. The time now is 11:32 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting