Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

variable variables

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

variable variables

Postby quaiz » Mon Nov 11, 2002 7:00 pm

First off, yes, i am a newbie and i apologize if this is a stupid questions. But, i can't find an answer anywhere.

I am trying to run a "for" loop that increments. Here is the code:

$seq_price = array( "1"=>395, "2"=>450, "3"=>300 ); //Sequence Pricing
$cha25_price = array( "1"=>155, "2"=>150, "3"=>100 ); //25 RXN Chariot Pricing
$cha100_price = array( "1"=>330, "2"=>240, "3"=>240 ); //100 RXN Chariot Pricing
$mod_price = array( "1"=>100, "2"=>120, "3"=>100 ); //Modification Pricing
$control_price = array( "1"=>100, "2"=>120, "3"=>100 ); //Extra Control Pricing
########################################################################
#SEQUENCE PRICING LOOP
########################################################################
for ($x=1; $x <= 10; $x++)
{
$seq="seq$x";
if ($$seq != "" ) //Price for sequence itself
{
$seqpr="seqpr$x";
($$seqpr = $seq_price["$cnum"]);

$mod="modpr$x";
if ($$mod != "none"){

$modpr="modpr$x";
$$modpr = $mod_price["$cnum"];
}

$cha="cha$x";
if ($cha == "25 rxns"){

$chapr="chapr$x";
$chapr = $cha25_price["$cnum"];
}

if ($cha == "100 rxns"){
$chapr = $cha100_price["$cnum"];
}

$septot="septot$x";
$$seqtot = ($$seqpr + $$modpr + $$chapr);
}
else
{
$seq="seq$x";
$$seq = 0;

$mod="modpr$x";
$$modpr = 0;

$cha="cha$x";
$$chapr = 0;
}
}
################
#NOTE: "cnum" is the country number defined by a hidden field in the form
################

Anyone have any clue why this does not work. Also is there a better way to define a variable so that it increments with each run of the loop?

Would appreciate any advice one can offer.
quaiz
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Nov 11, 2002 6:52 pm
Location: Carlsbad, CA

Postby DutchBen » Tue Nov 12, 2002 10:37 am

I'm sorry ... i'm not exactly sure what your trying to do here... maybe if you tell me what result you want i can better help you.

Gr. Ben
DutchBen
New php-forum User
New php-forum User
 
Posts: 36
Joined: Thu Oct 24, 2002 10:28 am
Location: Amsterdam

Postby quaiz » Tue Nov 12, 2002 12:32 pm

OK, here you go.

I have a form with 10 – 6 trimer sequences on it (ex. ACT AGT TGA ACC ATG ATC). I have another script that verifies the contents to make sure only DNA base pairs are used (A, C, T, and G). After that the code below is to be used to calculate the price of their sequences and create a total. I currently have this working if I process each sequence individually with this code (with x being replaced the sequence number):


########################################################################
# SEQUENCE X PRICING
########################################################################

if ( $seq1_X != "" ) //Price for sequence
$seqprX = $seq_price[$cnum];
#####
if ( $modX == "none" ) //Price for modification
$modprX = 0;
else
$modprX = $mod_price[$cnum];
#####
if ( $chaX == "none" ) //Price for no chariot kit
$chaprX = 0;
elseif ( $chaX == "25 rxns" ) //Price for a 25 rxn chariot kit
$chaprX = $cha25_price[$cnum];
elseif ( $chaX == "100 rxns" ) //Price for a 100 rxn chariot kit
$cha1pr = $cha100_price[$cnum];
#####
$seqtotX = ($seqprX + $modprX + $chaprX); // Calculates the total

If I can get this working in a loop then I can exit out of the loop if the researcher enters less than 10 sequences. At the end of these 10 repetitions I have this:

########################################################################
# Calculation of Positive Control Total
########################################################################
$poscontot = $ctrl * $control_price[$cnum];

########################################################################
# Calculation of Order Total
########################################################################
$ordertotal = ( $seqtot1 + $seqtot2 + $seqtot3 + $seqtot4 + $seqtot5 +
$seqtot6 + $seqtot7 + $seqtot8 + $seqtot9 + $seqtot10 +
$poscontot);

So, as you can see I use the result of the ten sequence calculation to get the final $ordertotal, which is passed on (along with all the other info on the order page and $seqtotX for each sequence) to a confirmation page.
quaiz
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Nov 11, 2002 6:52 pm
Location: Carlsbad, CA


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.