calculation
Posted: Thu Apr 06, 2006 6:46 am
Pimptastic | Please use
Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hey
This is what i'm trying to do :
I have a table "yacht_basket", that contains a parent field and every product bought will get the parent value of "1" in the table.
I want to SUM the parent field for the last session_id, and then :
if parent = 3
then take 1% off the total price. ( i have a price variable already called total, stored in the session ) $_SESSION['total'] = $total;}
so i want to take this total and do take 1% off the value, obviously if parent doesnt = 3 then just use the original value.
I am very new to php, but this is what i have so far, i dont know if i'm on the right lines though.
any advice would be greats, thanks
----------------------------------------------------------------------------------------------------------------------Code: Select all
<?php
$last_id = mysql_insert_id();
$result=mysql_query("SELECT * FROM yacht_basket where session_id = $session_id");
if (mysql_errno()!=0)
{
echo mysql_error(); This will select the last session id
exit;
}
?>
<?php
$res3 = mysql_query("SELECT SUM(parent) from `yacht_basket` WHERE`yacht_basket`.`session_id` = '$session_id'");
echo mysql_error(); // SUMS the parent column for products of the session_id
while ($row = mysql_fetch_assoc($res3)) {
if(parent=='3')
$total=(($total/100)*99);} //Calculation
?>Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]