Jump to content

Transfering array thru querry string


Memon

Recommended Posts

Normally we use a querry string to transfer variables. For instance;

http://www.example.com/test.ph?var1=$var1&var2=$var2

If $var1 & $var2 are simple string variables, it is ok.

But I want to pass some arrays to new page. Is it possible to pass thru querry string?

Link to comment
Share on other sites

I tried with serialize function, but still it is not going properly.

I used this code in first page:

$serial_array = serialize($my_array);
echo "<A HREF='test.php?no=$item_no&my_array=$serial_array'>Item</A>";

In the next page (test.php), I used this code:

$item_no=$_GET['no'];
$my_array=unserialize($_GET['my_array']);

But when I echo the "$my_array" array, it gives nothing.

However, if I echo it without unserializing, it gives the long serialzied string.

Link to comment
Share on other sites

If you really need to pass that much data around you might be doing something wrong. You generally only need to pass an identifier which can then be used to reconstruct any data you need on a new page.

 

Having said that, maybe sessions would be a better alternative because they can easily hold more complex data.

Link to comment
Share on other sites

I agree with thorpe.  Sessions are probably a better alternative.

 

However, if the array is not that large in terms of content, you might do:

<?php
$serial_array = htmlentities( urlencode( serialize($my_array) ), ENT_QUOTES );
echo "<A HREF='test.php?no=$item_no&my_array=$serial_array'>Item</A>";
?>

Link to comment
Share on other sites

Thanks for advise, Thrope.

But still I would like to know what is problem with my coding.

Secondly, I thought that session is suitable for storing only small data.

 

OK, let me explain the use of this site.

The first page reads the 'Stock List' from file & displays the list. But visitors can set some criteria/conditions, so only filtered data is displayed there. It is about 40 to 50 records. SOme details is displayed on this list.

When visitor clicks the stock number of any single item, full details are shown on next page, with photos of that item. For that purpose, I am using stock number to be included in query string, & details page again read that record from stock list.

This part is working fine. But user has to go back to original list, to see the details of different item. I need "Next" & "Previous" buttons on that details page, so that user can just see the next item of his filtered list, without going back.

For that, I need to transfer the filtered stock list to "details.php" page. Pls guide me if there is any better way.

Link to comment
Share on other sites

Thanks Rooput18.

 

I will try with corrected code later.

But just for yr info, the array consist of 40 to 50 'records', each of which has 10 'fields'.

All fields are 'text' & not special characters are used. Just alpha-numerical characters. Short fields have 4 or 5 characters, whereas longest one has 25  characters.

 

Do I need to use session for this purpose?

Link to comment
Share on other sites

I wouldn't use the URL for that amount of data.  Some browsers restrict the length of URLs they will allow so it may become truncated.  I would store it in the session and access it on the next page via the session.

 

You can store whatever you want in the session.  Small data.  Big data.  Persistent database connections.  Persistent configuration data.

Link to comment
Share on other sites

Thanks Rooput18.

 

I will try with corrected code later.

But just for yr info, the array consist of 40 to 50 'records', each of which has 10 'fields'.

All fields are 'text' & not special characters are used. Just alpha-numerical characters. Short fields have 4 or 5 characters, whereas longest one has 25  characters.

 

Do I need to use session for this purpose?

 

I'd use sessions for ANYTHING <3

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.