NYCPHP Meetup

NYPHP.org

[nycphp-talk] url pass array as parameter

chad qian nynj.tech at hotmail.com
Tue Jul 1 10:05:47 EDT 2008


Thanks for everyone answer my question!
 
One further question:
if
url=galleryform.php?$cartStr='cart[0]=val1&cart[1]=val2';
 
then
On gallery.php page:
<?php$totalcart=new array()
$totalcart=$_GET['cartStr']
for($x=0;$x<$totalcart[].length;$x++)
{echo   $totalcart[$x];
}  ?>
 
Is gallery.php coding is correct?I want to output array.
 
Thanks again!
 
> Date: Tue, 1 Jul 2008 06:24:17 -0400> To: talk at lists.nyphp.org> From: kenrbnsn at rbnsn.com> Subject: Re: [nycphp-talk] url pass array as parameter> > At 12:13 AM 7/1/2008, Anirudh Zala wrote:> >On Tuesday 01 Jul 2008 03:09:48 Tim Lieberman wrote:> > > Passing arrays in a query string is the wrong way to do it. Too many> > > things can go wrong.> >> >True. It is not proper way. But if you still want to pass such data using GET> >method then you can build Query string as shown below:> >> >$cartStr='cart[0]=val1&cart[1]=val2'; // assuming that array keys are> >numeric.> > You can take advantage of the mechanism in PHP that's used to use > arrays in forms:> > <?php> $cart = array('item one','item two','item three');> $urlstr = 'gallery.php?final[]=' . implode('&final[]=',$cart);> echo '<a href="' . $urlstr . '">Go</a>';> ?>> > Then in gallery.php> <?php> if (isset($_GET['final']))> echo implode("<br>\n",$_GET['final']);> ?>> > Ken> > > > > _______________________________________________> New York PHP Community Talk Mailing List> http://lists.nyphp.org/mailman/listinfo/talk> > NYPHPCon 2006 Presentations Online> http://www.nyphpcon.com> > Show Your Participation in New York PHP> http://www.nyphp.org/show_participation.php
_________________________________________________________________
It’s a talkathon – but it’s not just talk.
http://www.imtalkathon.com/?source=EML_WLH_Talkathon_JustTalk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080701/78c01509/attachment.html>


More information about the talk mailing list