PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
----------------------------------------------------------------------------------------------------------------------
<?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
?>
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]
i have another calculation if the products = 4( 4 is max they can have, i will do this one after thought)
my code above gets parsed without errors, but the price isnt getting 1 percent taken off.
is there a way i can check if the parent field is getting added up by making it into a variable or something and then seeing what value is getting put into there.
my whole script is below, maybe i have put something in the wrong order, as the Total variable is getting calculated above also.
not sure myself