Jump to content

[SOLVED] Quick Question


rn14

Recommended Posts

This is where create a new object and pass values to it. I know it fills this with values as when i print out the values on this page they display.

 

include('class.php');

$order = new Order();
$meallist = array();
foreach ($_REQUEST as $k=>$v) { if ($k=="meal") { $meallist = $v; } }
$order->Test($meallist); 

 

My problem occurs when i attempt to print these values out on a different page using the following code:

 

<?
include('class.php');
$array = $order->getData();
$meal1 = $array[0];
$meal2 = $array[1];
$meal3 = $array[2];
$meal4 = $array[3];
$meal5 = $array[4];
$meal6 = $array[5];
$meal7 = $array[6];

?>

I get this error:

Fatal error: Call to a member function getData() on a non-object.

 

Could anyone help?

 

 

Thanks

Link to comment
Share on other sites

You can save objects into the SESSION array, and then retrieve them on other pages just like you would any other variable. The only thing to remember is you need to load all of your classes (if you don't have an autoloader) before you call session_start().

Link to comment
Share on other sites

if these are two objects that i have in sesssions how will I add them to the session array??

 

if these are two objects that i have in sessions below How will I add them to the session array?

session_start();
include('class.php');

if (isset($_SESSION['order'])) {
      $order = unserialize($_SESSION['order']);
}else {
   $order = new Order();
}
// incase we want to reset our test data.
if ($_REQUEST['reset'] == "ok") {
   $order = new Order();
}
$meallist = array();
foreach ($_REQUEST as $k=>$v) { if ($k=="meal") { $meallist = $v; } }
$order->Test($meallist); //changed this to reference index of 0.
$_SESSION['order'] = serialize($order);
?>

<?
//order +1
if (isset($_SESSION['orderp2'])) {
      $orderp2 = unserialize($_SESSION['orderp2']);
}else {
   $orderp2 = new Order();
}
// incase we want to reset our test data.
if ($_REQUEST['reset'] == "ok") {
   $orderp2 = new Order();
}
$meallist = array();
foreach ($_REQUEST as $k=>$v) { if ($k=="meal2") { $meallist = $v; } }
$orderp2->Test($meallist); //changed this to reference index of 0.
$_SESSION['orderp2'] = serialize($orderp2);
?>
[code]

Thanks

Link to comment
Share on other sites

that is the code for 2 separate files right?

 

<?php
session_start();
include('class.php');

if (isset($_SESSION['order'])) {
   $order = $_SESSION['order'];
}else {
   $order = new Order();
}
// incase we want to reset our test data.
if ($_REQUEST['reset'] == "ok") {
   $order = new Order();
}
$meallist = array();
foreach ($_REQUEST as $k=>$v) { if ($k=="meal") { $meallist = $v; } }
$order->Test($meallist); //changed this to reference index of 0.
$_SESSION['order'] = $order;
?>

 

<?php
session_start();
include('class.php');

//order +1
if (isset($_SESSION['orderp2'])) {
   $orderp2 = $_SESSION['orderp2'];
}else {
   $orderp2 = new Order();
}
// incase we want to reset our test data.
if ($_REQUEST['reset'] == "ok") {
   $orderp2 = new Order();
}
$meallist = array();
foreach ($_REQUEST as $k=>$v) { if ($k=="meal2") { $meallist = $v; } }
$orderp2->Test($meallist); //changed this to reference index of 0.
$_SESSION['orderp2'] = $orderp2;
?>

Link to comment
Share on other sites

the SESSION is shared across the entire visit for a particular user. So, when the user navigates from page to page, the info in SESSION can be written to/read from. If, on page1.php, you store a value into $_SESSION['order'], then on page2.php you can read the value from $_SESSION['order'].

 

Does that make more sense?

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.