Could someone tell me how to print out each element of $_Session['order'] so that the output looks like:

pose
quantity
size
finish

pose
quantity
size
finish

Is there something wrong with

$formArray=array($pose,$quantity,$size,$finish);
array_push($_SESSION['order'],$formArray);

foreach ($_SESSION['order'] as $tempArray)
{
print $tempArray[0] . "<br />\n";
print $tempArray[1] . "<br />\n";
print $tempArray[2] . "<br />\n";
print $tempArray[3] . "<br />\n";
print "<br />";
}

session_start();

$_SESSION['order'];
$_SESSION['totalPrice'];
$_SESSION['basicCost'];
$_SESSION['finishUpgrade'];
$_SESSION['totalBasicPoints'];
$_SESSION['productNumber'];
    if (array_key_exists('_submit_check', $_POST)) {

$pose = $_POST['pose'];
$quantity = $_POST['quantity'];
$size = $_POST['size'];
$finish = $_POST['finish'];
$gallery = $_POST['gallery'];
$retouch = $_POST['retouch'];
$cards = $_POST['cards'];
$proofs = $_POST['proofs'];

$formArray=array($pose,$quantity,$size,$finish);
array_push($_SESSION['order'],$formArray);

foreach ($_SESSION['order'] as $tempArray)
{
print $tempArray[0] . "<br />\n";
print $tempArray[1] . "<br />\n";
print $tempArray[2] . "<br />\n";
print $tempArray[3] . "<br />\n";
print "<br />";
}

$_SESSION["productNumber"] += 1;

include 'sizeCase.php';
  $basicPoints*=$quantity;

 include 'finishCase.php';

 $_SESSION['finishUpgrade']*=10;
 $_SESSION['upgradedPrice']= $_SESSION['finishUpgrade'] + $basicCost;

$_SESSION['totalBasicPoints'] += $basicPoints;

$basicPoints = $_SESSION['totalBasicPoints'];
$extraPoint = 0;

include 'packageCase.php';

 $_SESSION['basicCost'] = $basicCost;
 $_SESSION['extraPoint'] = $extraPoint;
 $_SESSION['upgradedPrice']= $_SESSION['finishUpgrade'] + $basicCost;


print "total Basic Points are ". $_SESSION['totalBasicPoints'] ."<br />\n";
print "productNumber is ". $_SESSION["productNumber"] ."<br />\n";
print "totalPrice is ". $_SESSION['totalPrice'] ."<br /> \n";
print "basic Price is ". $_SESSION['basicCost'] ."<br /> \n";
print "Finish Upgrade is ". $_SESSION['finishUpgrade'] ."<br /> \n";
print "You get " .$_SESSION['extraPoint']. " extra points. <br />\n";
print "The Upgraded Cost is ". $_SESSION['upgradedPrice']. "<br />\n";

}

    And if you want to have it displayed neatly in HTML just put HTML <pre></pre> tags around the print_r();

    • off topic*
      pat1434, you do realise your site has directory browsing enabled

      when I use print_r(), it acts as if there's only one array, and it's being overwritten by the new form submission

      
      $formArray=array($pose,$quantity,$size,$finish);
      array_push($_SESSION['order'],$formArray);
      
      foreach ($_SESSION['order'] as $tempArray)
      {
      print_r($tempArray);
      }
      
      

        try using:

        $_SESSION['order'][] = $formArray;
        
        echo '<pre>';
        foreach($_SESSION['order'] as $key=>$array)
        {
          print_r($array);
        }
        echo '</pre>';

          With that code, the array doesn't print out at all. As far as I can see, it looks like it should be printing out, but no dice ???

            huh.. works for me...

            what does a [man]var_dump($_SESSION)[/man] do for you?

              var_dump($_SESSION) prints out the array - sample output is below. However,

              print $tempArray[0] . "<br />\n";
              print $tempArray[1] . "<br />\n";
              print $tempArray[2] . "<br />\n";
              print $tempArray[3] . "<br />\n";
              print "<br />";

              doesn't seem to work. What could be the problem?

              output from var_dump($_SESSION)

              array(7) { ["order"]=> array(29) { [0]=> array(4) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(4) "8x10" [3]=> string(5) "basic" } [1]=> NULL [2]=> array(4) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(4) "8x10" [3]=> string(5) "basic" } [3]=> NULL [4]=> array(4) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(4) "8x10" [3]=> string(5) "basic" } [5]=> NULL [6]=> array(4) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(4) "8x10" [3]=> string(5) "basic" } [7]=> NULL [8]=> array(4) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(4) "8x10" [3]=> string(5) "basic" } [9]=> NULL [10]=> array(4) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(4) "8x10" [3]=> string(5) "basic" } [11]=> NULL [12]=> array(4) { [0]=> string(1) "1" [1]=>

                change $tempArray[0] to
                $tempArray[0][0]
                $tempArray[0][1]
                etc. etc.

                Although, this loop should work:

                foreach($_SESSION as $key=>$val)
                {
                  echo '<b>'.$key.'</b><br>';
                  if($key == 'order' && is_array($_SESSION[$key])
                  {
                    foreach($_SESSION[$key] as $key2=>$val2)
                    {
                      echo '&nbsp;&nbsp;<i>'.$key2.'</i><br>';
                      if(is_array($_SESSION[$key][$key2]))
                      {
                        foreach($_SESSION[$key][$key2] as $key3=>$val3)
                        {
                          echo '&nbsp;&nbsp;&nbsp;&nbsp;'.$val.'<br>';
                        }
                      }
                    }
                  }
                  else
                  {
                    echo '$_SESSION["'.$key.'"] isn\'t an array, or it\'s not "order".  Sorry.<br>';
                  }
                }

                That should work. Not sure why the regular print_r won't.

                Have you tried:

                $order = $_SESSION['order'];
                echo '<pre>';
                print_r($order);
                echo '<br><br>';
                foreach($order as $key=>$array)
                {
                  var_dump($array);
                }

                  The app seems to be working with

                  $formArray=array($pose,$quantity,$size,$finish);
                  
                   $_SESSION['order'][] = $formArray;
                  
                  foreach ($_SESSION['order'] as $tempArray)
                  	{print print $tempArray[0] . "<br />\n";
                  print $tempArray[1] . "<br />\n";
                  print $tempArray[2] . "<br />\n";
                  print $tempArray[3] . "<br />\n";
                  print "<br />";
                  }
                  

                  but I have no clue whatsoever as to why. It seems to be the same code that I've been troubleshooting for the past two days.

                  Anyway, if it works, it works

                  Thanks for all the help!!!

                    Write a Reply...