TimeJunky Posted June 30, 2004 Posted June 30, 2004 I want to pass an array including values to another part of the php-script. e.g. $selected_files = { 12 2 4 5} After defining the variable, I intend to pass it as a hidden field of a form. echo tep_draw_hidden_field('check_files', $HTTP_POST_VARS['selected_files']); Afterwards, I tried to read it on the other part with it values $selected_files = $HTTP_GET_VARS['check_files']; However, I faild with that attemp. What is the correct way of passing arrays? :blink:
gazzzzzza Posted June 30, 2004 Posted June 30, 2004 i think you have to get an array first to set an array use $variable_array_name=array(); then to add stuff to an array use $variable_array_name[]=$input_number; to get the numbers out use Foreach($variable_array_name as $name) { echo $name; } i think to pass it use echo tep_draw_hidden_field('check_files', $variable_array_name[]); try that hope it works! always here to offer some useless advice....
TimeJunky Posted July 1, 2004 Author Posted July 1, 2004 thx, for the guide. Unfortunately, it is not working :( For testing purpose I defined: $variable_array_name[12]=121212; ..... echo tep_draw_hidden_field('check_files', $variable_array_name[]); after passing, I tried to get the value back without luck: $selected_files = $HTTP_POST_VARS['check_files'][1]; echo 'huhu12 - ' . $selected_files[12]; Maybe you know what's wrong again?
AXM Posted July 1, 2004 Posted July 1, 2004 Instead of passing it as a hidden field can you register the variable into the session id? I think the code is: tep_register($VARIABLE); It will store the variable in the session table like the customer's shopping cart content, current currency, language, etc is stored. The variable will be stored as long as the session ID is still in the address line and the session didn't expire. I'm not sure how this works when cookies are being used. But Hopefully ALL the detail in the session table is instead on a client-side cookie without you having to code any extra. I ♥ PHP/MYSQL/CSS
Guest Posted July 1, 2004 Posted July 1, 2004 you can't pass array as array, but use php behavior who reconstruct array. for this, one method could be: //the array $variable_array_name=array(12,15,25,87,2); //to pass the variables, note the [] after you variable name Foreach($variable_array_name as $name) echo tep_draw_hidden_field('check_files[]', $name); //then, in your receiving script, $variable_array_name=HTTP_GET_VARS['check_files'] and you have recreate the array from the precedent page Hope it helps
Recommended Posts
Archived
This topic is now archived and is closed to further replies.