feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
PHP Version: 5.1.0RC1
PHP OS: WINNT
Error Reporting: 2039 (E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_WARNING | E_ERROR)
Register Globals: On
Short Tags: On
Display Errors: On
Thats the result i get from running the code you gave me....
For the second reply, i tried that method and it dint work, i will paste my chunk of code to handle the cart for you to see.......Trying to implement it as a class at the first stage but ran into these problems. I dunno if i am using a right way by having arrays in class or shouldd i use another data structure to handle it ... Please advise, masters of php
Code: Select all
<?php
session_start();
class cart
{
var $cartItem = array();
var $label_cartItem = array();
var $combine_array = array();
var $test;
function cart()
{
$this->test = "session testing";
}
function initializeCart($numberOfItems)
{
for($i=0;$i<$numberOfItems;$i++)
{
$this->cartItem[$i]= array();
}
}
function combine_cart_array($label_cartItem,$value_arrays)
{
$this->label_cartItem = $label_cartItem;
if(is_array($this->label_cartItem) && is_array($value_arrays))
{
$combine = array();
$count = count($value_arrays);
$j = 0;
foreach ( $this->label_cartItem as $value)
{
$this->combine_array[$value] = $this->cartItem[$j];
$j++;
}
//return $combine;
}
else
{
return false;
}
}
}
$username = $_SESSION['username'];
//Declare cart array
if ( !isset($_SESSION['cartInfo']))
{
{
$_SESSION['cartInfo'] = array();
$_SESSION['cartCounter'] = 0 ;
}
}
else
{
if(isset($HTTP_POST_VARS['cartInit']) && $HTTP_POST_VARS['cartInit']="true" )
{
unset($HTTP_POST_VARS['cartInit']);
$counter = $_SESSION['cartCounter'];
$cartObject= new cart();
$cartObject->initializeCart(8);
$cartObject->label_cartItem = array("cartCategory","cartDescription","cartPrice","fabricInfo","styleInfo","galleryInfo");
$cartObject->combine_cart_array(($cartObject->label_cartItem),($cartObject->cartItem));
$_SESSION['cartInfo'][$counter] = $cartObject;
//session_register("cartObject");
$counter = $counter+1;
$_SESSION['cartCounter'] = $counter;
}
if(isset($HTTP_POST_VARS['cartItemName']) && $HTTP_POST_VARS['cartItemName']="Style")
{
unset($HTTP_POST_VARS['cartItemName']);
$styleId2 = $HTTP_POST_VARS['styleId'];
$styleId = array();
$where = " styleId = '$styleId2'";
$styleName = array();
$description = array();
$styleCode1 = array();
$category = array();
$styleCode2 = array();
$image = array();
$styleId = $dbfunctions->db_values_array("style","styleId","","styleId",$where);
$styleName = $dbfunctions->db_values_array("style","styleName","","styleId",$where);
$styleCode1 = $dbfunctions->db_values_array("style","styleCode1","","styleId","$where");
$styleCode2 = $dbfunctions->db_values_array("style","styleCode2","","styleId","$where");
$description = $dbfunctions->db_values_array("style","description","","styleId",$where);
$category = $dbfunctions->db_values_array("style","category","","styleId",$where);
$image = $dbfunctions->db_values_array("style","image","","styleId","$where");
$styleInfo = array();
$styleInfo = $dbfunctions->combine_db_arrays(array("styleId","styleName","styleCode1","styleCode2","description","category","image"), array(0=>$styleId,1=>$styleName,2=>$styleCode1,3=>$styleCode2,4=>$description,5=>$category,6=>$image));
$counter = $_SESSION['cartCounter'] - 1;
$_SESSION['cartInfo'][$counter]->combine_array['styleInfo']= $styleInfo;
}
}
$counter = $_SESSION['cartCounter'] - 1;
echo $counter;
echo $_SESSION['cartInfo'][$counter]->combine_array['styleInfo']['styleName'][0];
//$cartObject->test;
?>
The wierd thing about this code is that, if i take out the if($HTTP_POST_VARS) and if(isset($_SESSION['cartObject]) statement everything seems to be working fine when i view the cart, but if i put even one of it back then nothing shows, seems like the object disappears or something. Also this happens only when i try to show the information on the same page, i.e. cart.php, by clicking to other links and back to this one. But if i try to show the result on a page called test.php the session seems to be intact and working fine, and i still cant get the trouble of having to paste the code for class declaration on the top of eveypage out.

VERY confusing.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]