Sending two dynamic arrays via post data, then reading

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Sending two dynamic arrays via post data, then reading

Post by robster »

Hi all, I have two arrays, one array contains dates and the other matching array contains info for each date.

ie:

Code: Select all

$date_range_array (contains X dates)
$client_info_array (contains info on each client for each of the dates in $date_range_array)
What I have is a dynamic image (graph) that is being created (using JPGraph + GD) and the only way I can display the image is to call an external php file via the <img> tag. (If I use a function or do it inline it just bails due to headers already sent error).

Based on that I have to get the two arrays sent to the php file via post (or get) data.

Given that the two arrays can change their length dependant on a user form input, how can I send the data to the php file via the post data, then once I've done that, how can I get the data from the post data (remembering it could be any length) to use it?

Pretty tricky.

Any help appreciated,

Rob
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Store the arrays in the session data, or if you must use post data, then echo the arrays into a hidden text field like so:

Code: Select all

<?php

echo "<input type=\"hidden\" name=\"myarraydata\" value=\"" . serialize($myArray) . "\" />";

?>
Then on the action page:

Code: Select all

<?php

$myArray = unserialize($_POST['myarraydata']);

?>

HTH :)
Post Reply