Jump to content

Calculation


suki2shoes

Recommended Posts

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]
<?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();                    [b]This will select the last session id[/b]
    exit;
    }
    ?>

    <?php
    $res3 = mysql_query("SELECT SUM(parent) from `yacht_basket` WHERE`yacht_basket`.`session_id`     = '$session_id'");                                
    echo mysql_error();                                  [b]SUMS the parent column for products of the session_id[/b]
    while ($row = mysql_fetch_assoc($res3)) {
    
    if(parent=='3')
    $total=(($total/100)*99);}                [b]  Calculation[/b]

    ?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.