Re: hrm... varaible varaibles and looping

From: Date: Tue, 14 Nov 2000 04:25:01 +0000
Subject: Re: hrm... varaible varaibles and looping
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-25115@lists.php.net to get a copy of this message
At 09:09 PM 11/13/2000 -0800, Lars Torben Wilson wrote: code is below......i have changed it a bit...and now i need something different...and on top of all that....i have a quick question....first teh question.... i'm hacking up a quick shopping cart..all it does it take the product id's and put them into a large variable for storing in a session......what other ways could i do this? i thought about mysql...but then decided against it because it was getting complicated to having to add fields and this and that.... and with the loop....look at the code now...its should be easier to understand... if (session_is_registered("cart")){
        while (explode (":",$cart)){
                $cartitem = "item[".$numofitems ."]";
                $$cartitem = $cartarray[$numofitems];
                $numofitems++;
                echo $cartitem;
        }
}else{
        session_register("cart");
        }
ok - first of all we check to see if the cart exists....if it does we continue...if not we exit......then i take the variable ($cart) and split it apart at the ':'s. the problem that i run in to is that i can't get the loop to stop looping when there is nothing more to be split because it is at the end of $cart. is there a way to do this? do i make sense? ~kurth
Kurth Bemis writes: look at this i have $cart with "fields" separated by ':'. i explode the variable...however..i can't get it to loop and add one to the variable that points to the array...i can't figure out how to lloop until the end of the array is reached.....any ideas? look at the code. Where's the loop? It's not quite clear what you're attempting to do here. Can you include the loop itself and explain a bit more exactly what effect you're going for? if (session_is_registered("cart")){
      $cartitem = "item[".$numofitems ."]"; //set cartitem to item[#]
      $cartarray = explode (":",$cart); //separate cart at the colons
      if ($cartarray){
              $$cartitem = $cartarray[$numofitems]; //make $$cartitem equal to item[#]
and then set that to cartarray[#]
              $numofitems++; //duh
              echo $cartitem;
      }elseif (!$cartarray){
      echo "done!";
      }
}else{
      session_register("cart");
      }
~kurth Kurth Bemis - Network/Systems Administrator, USAExpress.net/Ozone Computer There is no sin except stupidity. -- Oscar Wilde kurth@usaexpress.net | http://www.usaexpress.net/kurth PGP key available - http://www.usaexpress.net/kurth/pgp Fight Weak Encryption! Donate your wasted CPU cycles to Distributed.net (http://www.distributed.net) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net -- +----------------------------------------------------------------+
|Torben Wilson <torben@php.net>                     Netmill iTech|
|http://www.coastnet.com/~torben            http://www.netmill.fi|
|Ph: 1 250 383-9735                             torben@netmill.fi|
+----------------------------------------------------------------+
Kurth Bemis - Network/Systems Administrator, USAExpress.net/Ozone Computer There is no sin except stupidity. -- Oscar Wilde kurth@usaexpress.net | http://www.usaexpress.net/kurth PGP key available - http://www.usaexpress.net/kurth/pgp Fight Weak Encryption! Donate your wasted CPU cycles to Distributed.net (http://www.distributed.net)

« previous php.general (#25115) next »