If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Help with session arrays

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-04-09, 22:29
TommyGunn TommyGunn is offline
Registered User
 
Join Date: Jul 2009
Posts: 6
Help with session arrays

Hi I am trying to use a session array to create a very simple shopping cart using php with odbc, I think my code is fine so far but I have limited experience and so any help would be great.

my code so far is as follows

<?php
session_start();
$Conn = odbc_connect ('06', 'root', '');
$cprid = $_POST['sel_item'];
$cproduct = $_POST['sel_item_product'];
$cprice = $_POST['sel_item_price'];
$ctop = $_POST['sel_item_top'];
$cqty = $_POST['sel_item_qty'];

$_SESSION['cart'][] = array("productId" => $cprid,
"product" => $cproduct,
"price" => $cprice,
"ptopping" => $ctop,
"qty" => $cqty);


echo("<p>".$_SESSION['cart'][0]."</p>");

?>

however all this returns is the value array

Am I correct in assuming each time the values are posted to this page they will be adding into the array or am I missing something out. also how would I go about listing the items in the array? I am guessing that I am going be using a whie statement?

any help anyone can give me would be great.
Reply With Quote
  #2 (permalink)  
Old 08-05-09, 08:29
TommyGunn TommyGunn is offline
Registered User
 
Join Date: Jul 2009
Posts: 6
ok have made some progress and added

foreach($_SESSION['cart'] as $cart)
{
echo '<tr>';
foreach($cart as $item)
{
echo "<td>$item</td>";
}
echo '</tr>';
}

so now at list I know my array is working ad I an display a list of sort
but till cant see how to pull each key out to use as I need
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On