[PHP] beginner in PHP
Can someone tell me why this doesn't work? The $mycart array is fine and the $catalog array is also fine but nothing inside the if statement prints. I've tried other echo statements but nothing prints at all. while (list($key,$value) = each($mycart)) { if ($value == $catalog[itemcd]) { echo $catalog[unitprice]; } } Thanks Phil -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] beginner in PHP
itemcd is an element of the array.. like this... array ('itemcd' => 'book', 'itemdesc' => 'This book is great', 'unitprice' => '29.95'); -Original Message- From: Pushkar Pradhan [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:12 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] beginner in PHP Is itemcd a variable then it should be used as $itemcd? > Try this: > > echo "$catalog[unitprice]"; > > > in my experience I've only been able to use the echo() without the > quotation marks if I'm calling a function, for variables you need the > quotation marks. > > Hope this helps. > > > Phillip Perry wrote: > > >Can someone tell me why this doesn't work? > >The $mycart array is fine and the $catalog array is also fine but nothing > >inside the if statement prints. I've tried other echo statements but nothing > >prints at all. > > > >while (list($key,$value) = each($mycart)) > > { > > if ($value == $catalog[itemcd]) > > { > > > > echo $catalog[unitprice]; > > > > } > > } > > > > > >Thanks > > > >Phil > > > > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -Pushkar S. Pradhan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] beginner in PHP
Thanks but that doesn't work. -Original Message- From: Tom Ray [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 10:59 PM To: [EMAIL PROTECTED] Cc: Php Subject: Re: [PHP] beginner in PHP Try this: echo "$catalog[unitprice]"; in my experience I've only been able to use the echo() without the quotation marks if I'm calling a function, for variables you need the quotation marks. Hope this helps. Phillip Perry wrote: >Can someone tell me why this doesn't work? >The $mycart array is fine and the $catalog array is also fine but nothing >inside the if statement prints. I've tried other echo statements but nothing >prints at all. > >while (list($key,$value) = each($mycart)) > { >if ($value == $catalog[itemcd]) > { > > echo $catalog[unitprice]; > > } > } > > >Thanks > >Phil > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] beginner in PHP
Thanks, but that didn't work either -Original Message- From: Tom Rogers [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:32 PM To: [EMAIL PROTECTED]; Php Subject: Re: [PHP] beginner in PHP Hi itemcd and unitprice should be in quotes I think if they are keys in an array. $catalog["itemcd"] $catalog["unitprice"] Tom At 10:56 PM 12/06/2002 -0400, Phillip Perry wrote: >Can someone tell me why this doesn't work? >The $mycart array is fine and the $catalog array is also fine but nothing >inside the if statement prints. I've tried other echo statements but nothing >prints at all. > >while (list($key,$value) = each($mycart)) > { > if ($value == $catalog[itemcd]) > { > > echo $catalog[unitprice]; > > } > } > > >Thanks > >Phil > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] beginner in PHP
Array ( [0] => gerainiums [1] => roses [2] => roses [3] => roses [4] => roses ) Array ( [0] => Array ( [itemcd] => daisys [itemcat] => FL [itemdesc] => Daisys, seed package 200/250 cnt [unitprice] => 2.2 ) [1] => Array ( [itemcd] => gerainiums [itemcat] => FL [itemdesc] => Gerainiums, purple, seed package 25/30 cnt [unitprice] => 0.85 ) [2] => Array ( [itemcd] => roses [itemcat] => FL [itemdesc] => Rose, white, root clump bush - spring delivery [unitprice] => 35 ) [3] => Array ( [itemcd] => tomatoe [itemcat] => VG [itemdesc] => Tomatoe, Super-Burbee, seedling flat, 12 plants [unitprice] => 12.5 ) [4] => Array ( [itemcd] => cucumber [itemcat] => VG [itemdesc] => Cucumber seed package, Chyrnobyl hybrid cross 10cnt [unitprice] => 0.03 ) [5] => Array ( [itemcd] => habanero [itemcat] => HP [itemdesc] => Red Savina Habanero Pepper seeds -- 20cnt, not for export [unitprice] => 2.85 ) [6] => Array ( [itemcd] => snapdragon [itemcat] => FL [itemdesc] => Snap Dragons, yellow/orange mix, seed package 50cnt [unitprice] => 1.25 ) [7] => Array ( [itemcd] => tulip [itemcat] => FL [itemdesc] => Tulip bulbs ... spring delivery 8 sets [unitprice] => 42.5 ) [8] => Array ( [itemcd] => snappea [itemcat] => VG [itemdesc] => Sugar snap peas - seed package 25 count [unitprice] => 2 ) [9] => Array ( [itemcd] => marigold [itemcat] => FL [itemdesc] => Marigold - Traditional ... seed package 40 cnt [unitprice] => 3.15 ) [10] => Array ( [itemcd] => bellpepper [itemcat] => VG [itemdesc] => Green Bell Pepper - Sweet, seed package 30 cnt [unitprice] => 4 ) [11] => Array ( [itemcd] => tigerlilly [itemcat] => FL [itemdesc] => Tiger Lilly seedlings 10cnt [unitprice] => 5.2 ) [12] => Array ( [itemcd] => pequin [itemcat] => HP [itemdesc] => Pequin ornamental hot pepper seed, 150 count [unitprice] => 4.25 ) [13] => Array ( [itemcd] => seranno [itemcat] => HP [itemdesc] => Seranno Pepper - spicy! seed pack 42cnt [unitprice] => 1.25 ) [14] => Array ( [itemcd] => flamingo [itemcat] => LO [itemdesc] => Tacky plastic pink flamingo, each [unitprice] => 5.23 ) [15] => Array ( [itemcd] => stork [itemcat] => LO [itemdesc] => Tacky plastic stork, alienate the new mom! each [unitprice] => 7.25 ) [16] => Array ( [itemcd] => rabbit [itemcat] => LO [itemdesc] => Plastic lawn rabbit, multiplies less than real, each [unitprice] => 4.05 ) [17] => Array ( [itemcd] => barney [itemcat] => LO [itemdesc] => Barney the Giant Purple Dinosaur, take him please! [unitprice] => 0.25 ) [18] => Array ( [itemcd] => gargoyle [itemcat] => LO [itemdesc] => Gargoyle, plaster, for the goth in us all! [unitprice] => 25 ) ) -Original Message- From: Martin Towell [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:33 PM To: '[EMAIL PROTECTED]'; Php Subject: RE: [PHP] beginner in PHP send the results of putting these two line just before your while loop print_r($mycart); print_r($catalog); -Original Message- From: Phillip Perry [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 1:31 PM To: Tom Rogers; Php Subject: RE: [PHP] beginner in PHP Thanks, but that didn't work either -Original Message- From: Tom Rogers [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:32 PM To: [EMAIL PROTECTED]; Php Subject: Re: [PHP] beginner in PHP Hi itemcd and unitprice should be in quotes I think if they are keys in an array. $catalog["itemcd"] $catalog["unitprice"] Tom At 10:56 PM 12/06/2002 -0400, Phillip Perry wrote: >Can someone tell me why this doesn't work? >The $mycart array is fine and the $catalog array is also fine but nothing >inside the if statement prints. I've tried other echo statements but nothing >prints at all. > >while (list($key,$value) = each($mycart)) > { > if ($value == $catalog[itemcd]) > { > > echo $catalog[unitprice]; > > } > } > > >Thanks > >Phil > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] beginner in PHP
Array ( [0] => gerainiums [1] => roses [2] => roses [3] => roses [4] => roses [5] => roses ) 1 1 Your output is different from the last print_r that Tom had me do. I wonder why that is -Original Message- From: Tom Rogers [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:44 PM To: [EMAIL PROTECTED]; Php Subject: RE: [PHP] beginner in PHP Hi Then I guess you will have to add some debug code try this before the while loop and make sure your if ($value == $catalog["itemcd"]) will produce a match (and you do need the quotes really :) echo "".print_r($catalogue)."".print_r($mycart).""; Tom At 11:31 PM 12/06/2002 -0400, Phillip Perry wrote: >Thanks, but that didn't work either > >-Original Message- >From: Tom Rogers [mailto:[EMAIL PROTECTED]] >Sent: Wednesday, June 12, 2002 11:32 PM >To: [EMAIL PROTECTED]; Php >Subject: Re: [PHP] beginner in PHP > > >Hi >itemcd and unitprice should be in quotes I think if they are keys in an >array. >$catalog["itemcd"] >$catalog["unitprice"] > >Tom > >At 10:56 PM 12/06/2002 -0400, Phillip Perry wrote: > >Can someone tell me why this doesn't work? > >The $mycart array is fine and the $catalog array is also fine but nothing > >inside the if statement prints. I've tried other echo statements but >nothing > >prints at all. > > > >while (list($key,$value) = each($mycart)) > > { > > if ($value == $catalog[itemcd]) > > { > > > > echo $catalog[unitprice]; > > > > } > > } > > > > > >Thanks > > > >Phil > > > > > >-- > >PHP General Mailing List (http://www.php.net/) > >To unsubscribe, visit: http://www.php.net/unsub.php > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] beginner in PHP
I meant Martin :) sorry. -Original Message- From: Phillip Perry [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:44 PM To: Tom Rogers; Php Subject: RE: [PHP] beginner in PHP Array ( [0] => gerainiums [1] => roses [2] => roses [3] => roses [4] => roses [5] => roses ) 1 1 Your output is different from the last print_r that Tom had me do. I wonder why that is -Original Message- From: Tom Rogers [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:44 PM To: [EMAIL PROTECTED]; Php Subject: RE: [PHP] beginner in PHP Hi Then I guess you will have to add some debug code try this before the while loop and make sure your if ($value == $catalog["itemcd"]) will produce a match (and you do need the quotes really :) echo "".print_r($catalogue)."".print_r($mycart).""; Tom At 11:31 PM 12/06/2002 -0400, Phillip Perry wrote: >Thanks, but that didn't work either > >-Original Message- >From: Tom Rogers [mailto:[EMAIL PROTECTED]] >Sent: Wednesday, June 12, 2002 11:32 PM >To: [EMAIL PROTECTED]; Php >Subject: Re: [PHP] beginner in PHP > > >Hi >itemcd and unitprice should be in quotes I think if they are keys in an >array. >$catalog["itemcd"] >$catalog["unitprice"] > >Tom > >At 10:56 PM 12/06/2002 -0400, Phillip Perry wrote: > >Can someone tell me why this doesn't work? > >The $mycart array is fine and the $catalog array is also fine but nothing > >inside the if statement prints. I've tried other echo statements but >nothing > >prints at all. > > > >while (list($key,$value) = each($mycart)) > > { > > if ($value == $catalog[itemcd]) > > { > > > > echo $catalog[unitprice]; > > > > } > > } > > > > > >Thanks > > > >Phil > > > > > >-- > >PHP General Mailing List (http://www.php.net/) > >To unsubscribe, visit: http://www.php.net/unsub.php > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] beginner in PHP
Thanks Martin!! That really helped out a lot. And thanks to all who tried to help me. I appreciate it! I have one other question that is really not so much important as it is annoying, but I can't figure it out myself. I'm practicing with sessions. What I'm making..if you couldn't tell by the array output from before...is a test shopping cart. Now the annoyance is that when I click the checkout link it's just supposed to destroy the session and reset everything to 0 including the shopping cart. And also if an item is clicked, that item gets deleted. With both choices when I click once the session does get destroyed, but everything stays on the page until I refresh the page. I want the info to get reset when I click the link. Here's the delete and checkout code...remember they both do actually work, just not as I want. Any suggestions on how to make it refresh on a click only? / DELETE SHOPPING CART ITEMS function chout(){ session_destroy(); $mycart = array(); $cart_items = 0; echo "Thank you for shopping!"; } if ($action == delnow) { unset($mycart[$itemid]); } // END DELETE SHOPPING CART ITEMS if ($action == checkout) { chout(); } -Original Message- From: Martin Towell [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:55 PM To: '[EMAIL PROTECTED]'; Tom Rogers; Php Subject: RE: [PHP] beginner in PHP here's the revised loop $cat_cnt = count($catalog); while (list($key,$value) = each($mycart)) { for ($j = 0; $j < $cat_cnt; $j++) if ($value == $catalog[$j]["itemcd"]) { echo $catalog[$j]["unitprice"]; break; } } -Original Message- From: Martin Towell [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 1:50 PM To: '[EMAIL PROTECTED]'; Tom Rogers; Php Subject: RE: [PHP] beginner in PHP Ah! $catalog is a 2D array - any your if statement is expecting a 1D array... -Original Message- From: Phillip Perry [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 1:52 PM To: Tom Rogers; Php Subject: RE: [PHP] beginner in PHP I meant Martin :) sorry. -Original Message- From: Phillip Perry [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:44 PM To: Tom Rogers; Php Subject: RE: [PHP] beginner in PHP Array ( [0] => gerainiums [1] => roses [2] => roses [3] => roses [4] => roses [5] => roses ) 1 1 Your output is different from the last print_r that Tom had me do. I wonder why that is -Original Message- From: Tom Rogers [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:44 PM To: [EMAIL PROTECTED]; Php Subject: RE: [PHP] beginner in PHP Hi Then I guess you will have to add some debug code try this before the while loop and make sure your if ($value == $catalog["itemcd"]) will produce a match (and you do need the quotes really :) echo "".print_r($catalogue)."".print_r($mycart).""; Tom At 11:31 PM 12/06/2002 -0400, Phillip Perry wrote: >Thanks, but that didn't work either > >-Original Message- >From: Tom Rogers [mailto:[EMAIL PROTECTED]] >Sent: Wednesday, June 12, 2002 11:32 PM >To: [EMAIL PROTECTED]; Php >Subject: Re: [PHP] beginner in PHP > > >Hi >itemcd and unitprice should be in quotes I think if they are keys in an >array. >$catalog["itemcd"] >$catalog["unitprice"] > >Tom > >At 10:56 PM 12/06/2002 -0400, Phillip Perry wrote: > >Can someone tell me why this doesn't work? > >The $mycart array is fine and the $catalog array is also fine but nothing > >inside the if statement prints. I've tried other echo statements but >nothing > >prints at all. > > > >while (list($key,$value) = each($mycart)) > > { > > if ($value == $catalog[itemcd]) > > { > > > > echo $catalog[unitprice]; > > > > } > > } > > > > > >Thanks > > > >Phil > > > > > >-- > >PHP General Mailing List (http://www.php.net/) > >To unsubscribe, visit: http://www.php.net/unsub.php > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] beginner in PHP
I get the same thing...I have to click twice, or refresh the page to get rid of the info. -Original Message- From: Martin Towell [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 12:21 AM To: '[EMAIL PROTECTED]'; Php Subject: RE: [PHP] beginner in PHP try this for chout() function chout(){ global $mycart, $cart_items; session_destroy(); -Original Message----- From: Phillip Perry [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 2:18 PM To: Martin Towell; Tom Rogers; Php Subject: RE: [PHP] beginner in PHP Thanks Martin!! That really helped out a lot. And thanks to all who tried to help me. I appreciate it! I have one other question that is really not so much important as it is annoying, but I can't figure it out myself. I'm practicing with sessions. What I'm making..if you couldn't tell by the array output from before...is a test shopping cart. Now the annoyance is that when I click the checkout link it's just supposed to destroy the session and reset everything to 0 including the shopping cart. And also if an item is clicked, that item gets deleted. With both choices when I click once the session does get destroyed, but everything stays on the page until I refresh the page. I want the info to get reset when I click the link. Here's the delete and checkout code...remember they both do actually work, just not as I want. Any suggestions on how to make it refresh on a click only? / DELETE SHOPPING CART ITEMS function chout(){ session_destroy(); $mycart = array(); $cart_items = 0; echo "Thank you for shopping!"; } if ($action == delnow) { unset($mycart[$itemid]); } // END DELETE SHOPPING CART ITEMS if ($action == checkout) { chout(); } -Original Message- From: Martin Towell [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:55 PM To: '[EMAIL PROTECTED]'; Tom Rogers; Php Subject: RE: [PHP] beginner in PHP here's the revised loop $cat_cnt = count($catalog); while (list($key,$value) = each($mycart)) { for ($j = 0; $j < $cat_cnt; $j++) if ($value == $catalog[$j]["itemcd"]) { echo $catalog[$j]["unitprice"]; break; } } -Original Message- From: Martin Towell [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 1:50 PM To: '[EMAIL PROTECTED]'; Tom Rogers; Php Subject: RE: [PHP] beginner in PHP Ah! $catalog is a 2D array - any your if statement is expecting a 1D array... -Original Message- From: Phillip Perry [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 1:52 PM To: Tom Rogers; Php Subject: RE: [PHP] beginner in PHP I meant Martin :) sorry. -Original Message- From: Phillip Perry [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:44 PM To: Tom Rogers; Php Subject: RE: [PHP] beginner in PHP Array ( [0] => gerainiums [1] => roses [2] => roses [3] => roses [4] => roses [5] => roses ) 1 1 Your output is different from the last print_r that Tom had me do. I wonder why that is -Original Message- From: Tom Rogers [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:44 PM To: [EMAIL PROTECTED]; Php Subject: RE: [PHP] beginner in PHP Hi Then I guess you will have to add some debug code try this before the while loop and make sure your if ($value == $catalog["itemcd"]) will produce a match (and you do need the quotes really :) echo "".print_r($catalogue)."".print_r($mycart).""; Tom At 11:31 PM 12/06/2002 -0400, Phillip Perry wrote: >Thanks, but that didn't work either > >-Original Message- >From: Tom Rogers [mailto:[EMAIL PROTECTED]] >Sent: Wednesday, June 12, 2002 11:32 PM >To: [EMAIL PROTECTED]; Php >Subject: Re: [PHP] beginner in PHP > > >Hi >itemcd and unitprice should be in quotes I think if they are keys in an >array. >$catalog["itemcd"] >$catalog["unitprice"] > >Tom > >At 10:56 PM 12/06/2002 -0400, Phillip Perry wrote: > >Can someone tell me why this doesn't work? > >The $mycart array is fine and the $catalog array is also fine but nothing > >inside the if statement prints. I've tried other echo statements but >nothing > >prints at all. > > > >while (list($key,$value) = each($mycart)) > > { > > if ($value == $catalog[itemcd]) > > { > > > > echo $catalog[unitprice]; > > > > } > > } > > > > > >Thanks > > > >Phil > > > > > >-- > >PHP General Mailing List (http://www.php.net/) > >To unsubscribe, visit: http://www.php.net/unsub.php > > >-- >
RE: [PHP] beginner in PHP
Yes, here is the checkout code I used... function chout(){ session_destroy(); unset ($mycart); unset ($cart_items); echo "Thank you for shopping!"; } Any suggestions? -Original Message- From: Tim Ward [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 4:18 AM To: Martin Towell; Tom Rogers; Php; Phillip Perry Subject: RE: [PHP] beginner in PHP >From the symptoms it sounds like you're destroying the session okay but leaving the variables In the script. Are you sure you're unsetting them at the appropriate scope level. Tim Ward www.chessish.com <http://www.chessish.com> -- From: Phillip Perry [SMTP:[EMAIL PROTECTED]] Sent: 13 June 2002 05:18 To: Martin Towell; Tom Rogers; Php Subject: RE: [PHP] beginner in PHP Thanks Martin!! That really helped out a lot. And thanks to all who tried to help me. I appreciate it! I have one other question that is really not so much important as it is annoying, but I can't figure it out myself. I'm practicing with sessions. What I'm making..if you couldn't tell by the array output from before...is a test shopping cart. Now the annoyance is that when I click the checkout link it's just supposed to destroy the session and reset everything to 0 including the shopping cart. And also if an item is clicked, that item gets deleted. With both choices when I click once the session does get destroyed, but everything stays on the page until I refresh the page. I want the info to get reset when I click the link. Here's the delete and checkout code...remember they both do actually work, just not as I want. Any suggestions on how to make it refresh on a click only? / DELETE SHOPPING CART ITEMS function chout(){ session_destroy(); $mycart = array(); $cart_items = 0; echo "Thank you for shopping!"; } if ($action == delnow) { unset($mycart[$itemid]); } // END DELETE SHOPPING CART ITEMS if ($action == checkout) { chout(); } -Original Message- From: Martin Towell [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:55 PM To: '[EMAIL PROTECTED]'; Tom Rogers; Php Subject: RE: [PHP] beginner in PHP here's the revised loop $cat_cnt = count($catalog); while (list($key,$value) = each($mycart)) { for ($j = 0; $j < $cat_cnt; $j++) if ($value == $catalog[$j]["itemcd"]) { echo $catalog[$j]["unitprice"]; break; } } -Original Message- From: Martin Towell [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 1:50 PM To: '[EMAIL PROTECTED]'; Tom Rogers; Php Subject: RE: [PHP] beginner in PHP Ah! $catalog is a 2D array - any your if statement is expecting a 1D array... -Original Message- From: Phillip Perry [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 1:52 PM To: Tom Rogers; Php Subject: RE: [PHP] beginner in PHP I meant Martin :) sorry. -Original Message- From: Phillip Perry [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:44 PM To: Tom Rogers; Php Subject: RE: [PHP] beginner in PHP Array ( [0] => gerainiums [1] => roses [2] => roses [3] => roses [4] => roses [5] => roses ) 1 1 Your output is different from the last print_r that Tom had me do. I wonder why that is -Original Message- From: Tom Rogers [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 12, 2002 11:44 PM To: [EMAIL PROTECTED]; Php Subject: RE: [PHP] beginner in PHP Hi Then I guess you will have to add some debug code try this before the while loop and make sure your if ($value == $catalog["itemcd"]) will produce a match (and you do need the quotes really :) echo "".print_r($catalogue)."".print_r($mycart).""; Tom At 11:31 PM 12/06/2002 -0400, Phillip Perry wrote: >Thanks, but that didn't work either > >-Original Message- >From: Tom Rogers [mailto:[EMAIL PROTECTED]] >Sent: Wednesday, June 12, 2002 11:32 PM >To: [EMAIL PROTECTED]; Php >Subject:
RE: Re[2]: [PHP] beginner in PHP
Thank you but that didn't work. I still have to refresh the page. -Original Message- From: Stuart Dallas [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 2:53 PM To: Phillip Perry Cc: Tim Ward; Martin Towell; Tom Rogers; Php Subject: Re[2]: [PHP] beginner in PHP On Thursday, June 13, 2002 at 7:44:39 PM, you wrote: > Yes, here is the checkout code I used... > function chout(){ > session_destroy(); > unset ($mycart); > unset ($cart_items); > echo "Thank you for shopping!"; > } > Any suggestions? Try this... function chout(){ global $mycart, $cart_items; session_destroy(); unset ($mycart); unset ($cart_items); echo "Thank you for shopping!"; } And if it works, read this: http://www.php.net/manual/en/language.variables.scope.php -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] beginner in PHP
So how do I affect the local copies of the variables. The global() doesn't seem to work. Should I take everything out of the function and just use if statements? -Original Message- From: Tim Ward [mailto:[EMAIL PROTECTED]] Sent: Friday, June 14, 2002 3:46 AM To: [EMAIL PROTECTED]; Tim Ward; Martin Towell; Tom Rogers; Php Subject: RE: [PHP] beginner in PHP You're insetting the variables within the chout() function only This has no effect on the local copies as they are not in scope here. You have successfully destroyed the session so when you refresh they are unset. What I do with sessions is keep them all within a session array so you can then destroy the session locally by unsetting that array. If I have a function that I want to change session variables at all I make it take the session in as a parameter and pass it back as the return value. Tim Ward > -Original Message- > From: Phillip Perry [SMTP:[EMAIL PROTECTED]] > Sent: 13 June 2002 19:45 > To: Tim Ward; Martin Towell; Tom Rogers; Php > Subject: RE: [PHP] beginner in PHP > > Yes, here is the checkout code I used... > > function chout(){ > session_destroy(); > unset ($mycart); > unset ($cart_items); > echo "Thank you for shopping!"; > } > > Any suggestions? > > -Original Message- > From: Tim Ward [mailto:[EMAIL PROTECTED]] > Sent: Thursday, June 13, 2002 4:18 AM > To: Martin Towell; Tom Rogers; Php; Phillip Perry > Subject: RE: [PHP] beginner in PHP > > > From the symptoms it sounds like you're destroying the session okay but > leaving the variables > In the script. Are you sure you're unsetting them at the appropriate scope > level. > > Tim Ward > www.chessish.com <http://www.chessish.com> > > -- > From: Phillip Perry [SMTP:[EMAIL PROTECTED]] > Sent: 13 June 2002 05:18 > To: Martin Towell; Tom Rogers; Php > Subject: RE: [PHP] beginner in PHP > > Thanks Martin!! That really helped out a lot. And thanks to all who > tried to > help me. I appreciate it! > > I have one other question that is really not so much important as it > is > annoying, but I can't figure it out myself. > > I'm practicing with sessions. What I'm making..if you couldn't tell > by the > array output from before...is a test shopping cart. Now the > annoyance is > that when I click the checkout link it's just supposed to destroy > the > session and reset everything to 0 including the shopping cart. And > also if > an item is clicked, that item gets deleted. With both choices when I > click > once the session does get destroyed, but everything stays on the > page until > I refresh the page. I want the info to get reset when I click the > link. > Here's the delete and checkout code...remember they both do actually > work, > just not as I want. Any suggestions on how to make it refresh on a > click > only? > > / DELETE SHOPPING CART ITEMS > > function chout(){ > session_destroy(); > $mycart = array(); > $cart_items = 0; > echo "Thank you for shopping!"; > } > > if ($action == delnow) > { > unset($mycart[$itemid]); > } > > // END DELETE SHOPPING CART ITEMS > > if ($action == checkout) > { > chout(); > } > > -Original Message- > From: Martin Towell [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, June 12, 2002 11:55 PM > To: '[EMAIL PROTECTED]'; Tom Rogers; Php > Subject: RE: [PHP] beginner in PHP > > > here's the revised loop > > > $cat_cnt = count($catalog); > while (list($key,$value) = each($mycart)) > { > for ($j = 0; $j < $cat_cnt; $j++) > if ($value == $catalog[$j]["itemcd"]) > { > echo $catalog[$j]["unitprice"]; > break; > } > } > > > -Original Message- > From: Martin Towell [mailto:[EMAIL PROTECTED]] > Sent: Thursday, June 13, 2002 1:50 PM > To: '[EMAIL PROTECTED]'; Tom Rogers; Php > Subject: RE: [PHP] beginner in PHP > > > Ah! $catalog is a 2D array - any your if statement is expecting a 1D > array... > > -Original Message- > From: Phillip Perry [mailto:[EMAIL PR