Memon Posted February 20, 2010 Share Posted February 20, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/ Share on other sites More sharing options...
Alex Posted February 20, 2010 Share Posted February 20, 2010 Take a look at serialize Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/#findComment-1015127 Share on other sites More sharing options...
Memon Posted February 20, 2010 Author Share Posted February 20, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/#findComment-1015140 Share on other sites More sharing options...
trq Posted February 20, 2010 Share Posted February 20, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/#findComment-1015141 Share on other sites More sharing options...
roopurt18 Posted February 20, 2010 Share Posted February 20, 2010 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/#findComment-1015147 Share on other sites More sharing options...
Memon Posted February 20, 2010 Author Share Posted February 20, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/#findComment-1015149 Share on other sites More sharing options...
RussellReal Posted February 20, 2010 Share Posted February 20, 2010 sending an array via the url will make it hard to share the top url and other things.. but here is how you'd do it urll.com/theFile.php?data[]=firstElement&data[]=secondElement Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/#findComment-1015153 Share on other sites More sharing options...
Memon Posted February 20, 2010 Author Share Posted February 20, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/#findComment-1015154 Share on other sites More sharing options...
roopurt18 Posted February 20, 2010 Share Posted February 20, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/#findComment-1015162 Share on other sites More sharing options...
RussellReal Posted February 20, 2010 Share Posted February 20, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/#findComment-1015334 Share on other sites More sharing options...
Memon Posted February 21, 2010 Author Share Posted February 21, 2010 Thanks all for yr valuable advise. Quote Link to comment https://forums.phpfreaks.com/topic/192695-transfering-array-thru-querry-string/#findComment-1015470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.