Im trying to pass arrays via the url. I've tried the following:

 $sdatawk = serialize(urlencode($datawk));  
$sdatay = serialize(urlencode($datay));
$sdata = serialize(urlencode($data));

url looks like this:

graphcode.php?datawk=$sdatawk&datay=$sdatay&data=$sdata

on the receiving page:

$tdatawk= unserialize(urldecode($_GET['datawk'])); 
$tdata = unserialize(urldecode($_GET['datay'])); 
$tsdata = unserialize(urldecode($_GET['sdata'])); 

When I do a var_dump of any of the above, I get:

NULL

Please help me figure out what I'm doing wrong. Thanks in advance

    "urlencode()" takes a string argument, but you're passing it an array. Try switching "serialize()" and "urlencode()" around.

      I did try switching it around...

      It not returns: string(0) ""

      On the receiving page, the url looks like this after it is passed:

      datawk=a%3A13%3A%7Bi%3A0%3Bs%3A1.........

        Check the manual page for "urlencode()".

        At any rate, you can't pass an array to a function that requires a string.

          Check the manual page for "urlencode()" and problems to watch for with it.

          At any rate, you can't pass an array to a function that requires a string.

            Hmmm. Ok, I'll check it out. Thanks.

            So how is it that I would pass an array then. I need to be able to use it as an array on the output page in a graph I'm making.

              Ok this is what I have so far. I'm using it with jpgraph:

              This is my receiving page from the form. Only included the first if statement here

              $players = $_POST['subcat3'];
              $position = $_POST['cat'];
              $year = $_POST['subcat'];
              $fpydpt = $_POST['pass_yd'];
              $fpydper = $_POST['pass_ydper'];
              $fruydper = $_POST['rush_ydper'];
              $freydper = $_POST['rec_ydper'];
              $fptd = $_POST['pass_td'];
              $fruyd = $_POST['rush_yd'];
              $freyd = $_POST['rec_yd'];
              $fttd = $_POST['total_td'];
              $fin = $_POST['qbin'];
              $freatt = $_POST['rec_att'];
              
              $fpydcalc = ($fpydpt / $fpydper);
              $fruydcalc = ($fruyd / $fruydper);
              $freydcalc = ($freyd / $freydper);
              
              
              if (($_POST['pass_yd'] > 5) || ($_POST['pass_ydper'] > 50) || ($_POST['rush_yd'] > 3) || ($_POST['rush_ydper'] > 50) || ($_POST['rec_yd'] > 3) || ($_POST['rec_ydper'] > 50) || ($_POST['qbin'] < -5) || ($_POST['qbin'] > 0) || ($_POST['rec_att'] > 3) || ($_POST['pass_td'] > 10) || ($_POST['total_td'] > 10))
              	{
              	  echo "<B>Give me a break. Pick some real settings. <a href=\"graphmenu.php\">Try again</a></b><br><br>";
              }
              elseif (isset($_POST['subcat3']) && (isset($_POST['subcat'])) && (isset($_POST['ret'])))
              {
               if ($_POST['cat']== 1)
              	{
              
              $SQL = "SELECT * from playerstats ps, players p WHERE ps.player_id='".$_POST['subcat3']."'". " and p.player_id=ps.player_id and ps.year='".$_POST['subcat']."'". " ORDER BY ps.week ASC"; 
                 $RESULT = mysql_query($SQL);
               if ($myrow=mysql_fetch_array($RESULT)) {
                    do { 
              	 $year = $myrow["year"];
              	 $ptd[] = $myrow["pass_td"];
              	 $ryd[] = $myrow["rush_yd"];
                   $datawk[] = $myrow["week"]; 
                   $qbi[] = $myrow["qb_in"];
                   $data[] = $myrow["pass_yd"]; 
              	 $att[] = $myrow["pass_att"];
              	 $cmp[] = $myrow["pass_cmp"];
                   $data2[] = (($myrow['pass_yd'] * $fpydcalc) + ($myrow['pass_td'] * $fptd) + ($myrow['qb_in'] * $fin)  + ($myrow['rush_yd'] * $fruydcalc) + ($myrow['total_td'] * $fttd));
              	 $lastname = $myrow["lname"];
              	 $firstname = $myrow["fname"];	
                   $data_names[] = $myrow["lname"]."(".$players.")";
              }
              while ($myrow=mysql_fetch_array($RESULT)); 
                 }
              
                for ($n = 0; $n < max($datawk); $n++) {
                  if ($datawk[$n] != $n + 1) {
                      array_splice($datawk, $n, 0, (array) '-');
                      array_splice($data, $n, 0, (array) '0');
                      array_splice($ptd, $n, 0, (array) '0');
                      array_splice($data2, $n, 0, (array) '0');
                       } 
                 }
               $sdatawk = urlencode(serialize($datawk));  
              $sdata2 = urlencode(serialize($data2));
              $sdata = urlencode(serialize($data)); $scmp = urlencode(serialize($cmp)); $satt = urlencode(serialize($att)); $sqbi = urlencode(serialize($qbi)); $sryd = urlencode(serialize($ryd)); $sptd = urlencode(serialize($ptd)); echo "<img src=\"graphcode.php?pid=$players&pos=$position&year=$year&pypt=$fpydpt&pydp=$fpydper&datay=$sdata&datawk=$sdatawk&data2=$sdata2&ptd=$sptd&qbi=$sqbi&ryd=$sryd&cmp=$scmp&att=$satt&lname=$lastname&fname=$firstname&rydp=$fruydper&fruydp=$fruyd\">"; }

              Im trying to pass the arrays to the graphcode page, which does the actual graph rendering.

              That page looks like this:

              I've removed the actual graph code for sake of space, but it does work:

              $players = $_GET['pid'];
              $position = $_GET['pos'];
              $year = $_GET['year'];
              $tdatawk= urldecode(unserialize($_GET['datawk'])); 
              $tdata = urldecode(unserialize($_GET['datay'])); 
              $tdatay2 = urldecode(unserialize($_GET['datay2'])); 
              $tdata2 = urldecode(unserialize($_GET['data2'])); 
              $tqbi = urldecode(unserialize($_GET['qbi'])); 
              $tptd = urldecode(unserialize($_GET['ptd'])); 
              $tatt = urldecode(unserialize($_GET['att'])); 
              $tcmp = urldecode(unserialize($_GET['cmp'])); 
              $tryd = urldecode(unserialize($_GET['ryd'])); 
              $fpydpt = $_GET['pypt'];
              $fpydper = $_GET['pydp'];
              $fruydper = $_GET['rydp'];
              
              var_dump ($tdatawk);

                I couldn't manage to pass arrays via the URL on my own test server, but then again I wouldn't want to. The GET string is limited to something like 255 characters. At any rate, I would never try to pass arrays or something of that nature through the URL.

                Look into using sessions or cookies. (That's my opinion, anyway.)

                  OK I started messing with sessions, but Im a little stuck

                  My query:

                  $SQL = "SELECT * from playerstats ps, players p WHERE ps.player_id='".$_POST['subcat3']."'". " and p.player_id=ps.player_id and ps.year='".$_POST['subcat']."'". " ORDER BY ps.week ASC";
                     $RESULT = mysql_query($SQL);
                  if ($myrow=mysql_fetch_array($RESULT)) {
                        do {
                       $year = $myrow["year"];
                       $ptd[] = $myrow["pass_td"];
                       $ryd[] = $myrow["rush_yd"];
                       $datawk[] = $myrow["week"];
                       $qbi[] = $myrow["qb_in"];
                       $data[] = $myrow["pass_yd"];
                       $att[] = $myrow["pass_att"];
                       $cmp[] = $myrow["pass_cmp"];
                       $data2[] = (($myrow['pass_yd'] * $fpydcalc) + ($myrow['pass_td'] * $fptd) + ($myrow['qb_in'] * $fin)  + ($myrow['rush_yd'] * $fruydcalc) + ($myrow['total_td'] * $fttd));
                       $lastname = $myrow["lname"];
                       $firstname = $myrow["fname"];    
                  $data_names[] = $myrow["lname"]."(".$players.")"; } while ($myrow=mysql_fetch_array($RESULT)); } for ($n = 0; $n < max($datawk); $n++) { if ($datawk[$n] != $n + 1) { array_splice($datawk, $n, 0, (array) '-'); array_splice($data, $n, 0, (array) '0'); array_splice($ptd, $n, 0, (array) '0'); array_splice($data2, $n, 0, (array) '0'); } }

                  How would I send the below via a session:

                       $ptd[] = $myrow["pass_td"];
                       $ryd[] = $myrow["rush_yd"];
                       $datawk[] = $myrow["week"];
                       $qbi[] = $myrow["qb_in"];
                       $data[] = $myrow["pass_yd"];

                  I've tried several things, but they show as NULL on the receiving page. Any tips to get me started would be appreciated

                    Write a Reply...