Take the 2-minute tour ×

I have two pages:

  • Graph.php
  • List.php

The Graph page does exactly what it is named, graphs data. If there is no post/get data it displays all the data in a given table.

The List page is a huge table which loads around 500-600 rows of data. In the table you can sort and filter the rows using JavaScript. The table is around 14 columns wide.

After sorting the rows in the List page you can press a button 'Graph' that will take the visible rows and graph them on the graph page.

What I am having trouble with is passing these ID's over to the graph page. I started with:

    $afterSerializeArray = unserialize($_POST['data']);
    $beforeSerializeArray = array();
    $beforeSerializeArray[] = 1;
    $beforeSerializeArray[] = 2;
    $beforeSerializeArray[] = 3;
    $serializeArray = serialize($beforeSerializeArray);
<form action="" method="post">
<input type="hidden" name="data" value="<?php echo $serializeArray; ?>"/>
<input type="submit" value="Serialize"/>

I have written the small snippet to grab the ID's of the visible rows and load them into an array, serialize it and pump it into a variable to post it over to the graph.

Should I be using GET? Should I be doing this a different way?

The reason I wanted the filter and sort on a different page than the graph is because users have a lot of columns and options to filter and sort by.

share|improve this question
Don't use GET. it's generally limited to a max length by most browers, and if your serialized data gets silently truncated by the browser (and/or webserver), you'll just get nothing. Use POSt. it's (essentially) unlimited in length. –  Marc B Oct 1 '12 at 19:10
i would not post all the data from page one to two, i would post some way to identify the data and reselect it on page 2 for display. –  Dagon Oct 1 '12 at 19:10
Like @MarcB said, do not use GET. You could make ajax graph, that refreshes on any of your action. –  Glavić Oct 1 '12 at 19:11
@glavić Ajax graph or not you still need to pass it data - so it is safe to use post with a long serialized array? –  user1627928 Oct 1 '12 at 19:13
It is safe, why not? I would do it like @Dagon told you. –  Glavić Oct 1 '12 at 19:15
show 5 more comments

1 Answer

Rather than trying to send array over post you should concatenate these ids with any special character (say ','). This way you will get all IDs as comma separated values in $_POST['data']. Now you can use PHP explode function to get all the values in an array and use them as you wish.

This code sample might help you

    echo "FOUND Ids<br>";
    $IdArray = explode(',',$_POST['data']);
    print_r($IdArray );
    $idarray = array('1','2','3');
    $ids = implode(',',$idarray);
<form action="" method="post">
<input type="hidden" name="data" value="<?php echo $ids;?>"/>
share|improve this answer
Could you expand your answer a little, please? Why is it better to send data as a string rather than as an array? Is it just that it makes accessing it easier? –  andrewsi Oct 4 '12 at 14:42
Just BTW, you should read about implode() function –  Touki Oct 5 '12 at 6:44
thanks for reminding –  flawless Oct 5 '12 at 6:50
add comment

Your Answer


