If your checkbox name was cbox setup as <input type="checkbox" name="cbox"
value="true"> you could check for it like this

<?php
// if you have PHP 4.1+ use this code
if ($_REQUEST['cbox'] == 'true') {
        // do code
}
?>


You could also just check to make sure that the box variable is set rather
than comparing its value

<?php
if (isset($_REQUEST['cbox']) {
        // do code
}
?>

Jason
-----Original Message-----
From: jas [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 21, 2002 10:23 PM
To: [EMAIL PROTECTED]
Subject: [PHP] calculation based on checkbox


<?php
$ad = ereg_replace ("\"", "&q&", $ad);  # prevents an error when sending $ad
through an HTML form
$ad = ereg_replace ("'", "&a&", $ad);  # prevents a mysql error
$ad = ereg_replace ("%", "&p&", $ad); #prevents a mysql error
$ad = ereg_replace ("\\\\", "&bs&", $ad); #prevents a mysql error
# splits the ad into an array called $words
$words = split(" ", $ad);

# counts the number of expressions in the array
$num = count($words);

# variable used to check how many of the expressions are really spaces
$count2 = 0;

for($i = 0; $i < $num; $i++){ # determines if any variables are empty and if
they are $count goes up one to determine how many spaces there are in the
expressions
 if ($words[$count2] == "" ){
 $count = $count + 1;
 }
$count2 = $count2 + 1;
}

$num = $num - $count; #gets the new number of words

$price = 5.00;

if ($num > 10) { # if the users ad has more than 10 words in it than
$quarters = the extra words times .20
 $subtractor = $num - 10;
 $quarters = $subtractor * .20;
}
$subtotal = $price + $quarters; # price plus the number of words over 10
$total = $papers * $subtotal; # new price multiplied by number of papers
$total = $total * $weeks; # new new price multiplied by number of weeks
$total = sprintf ("%01.2f", $total);
?>
Here is part of my function thus far, and the output is a simple $$ based on
the number of words, I just need to add an IF statement to determine whether
or not I will need to subtract a certain amount if a checkbox is checked. I
am assuming that the IF statement would be something like...
IF $variable = 1; {
         $variable - $total = $total2
)
Else do the rest of the code...
I am still a newbie to php so any help would be great.
Thanks in advance,
Jas




-- 
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

Reply via email to