my 2 total r mixed with each other how can i separate them?
<p>i am going to create a online card exchange store where they can buy and sell their card so i made 2 cart system. 1 for incoming card and 1 for outgoing card. all is going well accept the total. here is my code please help me.</p>

<pre><code>&lt;?php
// cart function for card in 
function cardin () {
foreach($_SESSION as $name =&gt; $value) {
        if ($value &gt;0) {
            if (substr($name, 0, 5)=='cain_') {
                $id = substr($name, 5, (strlen($name)-5));
                $get = mysql_query('SELECT id, name, inprice FROM cards WHERE id='.mysql_real_escape_string((int)$id));
                while ($get_row = mysql_fetch_assoc($get)){
                    $sub = $get_row['inprice']*$value;
                echo '&lt;table align="center" width="900" border="1"&gt;
  &lt;tr&gt;
    &lt;td width="382" align="center"&gt;'.$get_row['name'].'&lt;/td&gt;
    &lt;td width="89" align="center"&gt;'.$value.'&lt;/td&gt;
    &lt;td width="121" align="center"&gt;' .$get_row['inprice'].'&lt;/td&gt;
    &lt;td width="124" align="center"&gt;'.$sub.'&lt;/td&gt;
    &lt;td width="79" align="center"&gt;&lt;a href="cart.php?removein='.$id.'"&gt;[-]&lt;/a&gt;&lt;/td&gt;
    &lt;td width="79" align="center"&gt;&lt;a href="cart.php?addin='.$id.'"&gt;[+]&lt;/a&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;';
                }
            }
        }
    }
}
// cart funciotn for out
function cardout () {
foreach($_SESSION as $name =&gt; $value) {
        if ($value &gt;0) {
            if (substr($name, 0, 5)=='caou_') {
                $id = substr($name, 5, (strlen($name)-5));
                $get = mysql_query('SELECT id, name, outprice FROM cards WHERE id='.mysql_real_escape_string((int)$id));
                while ($get_row = mysql_fetch_assoc($get)){
                    $sub = $get_row['outnprice']*$value;
                echo '&lt;table align="center" width="900" border="1"&gt;
  &lt;tr&gt;
    &lt;td width="382" align="center"&gt;'.$get_row['name'].'&lt;/td&gt;
    &lt;td width="89" align="center"&gt;'.$value.'&lt;/td&gt;
    &lt;td width="121" align="center"&gt;' .$get_row['outprice'].'&lt;/td&gt;
    &lt;td width="124" align="center"&gt;'.$sub.'&lt;/td&gt;
    &lt;td width="79" align="center"&gt;&lt;a href="cart.php?removeout='.$id.'"&gt;[-]&lt;/a&gt;&lt;/td&gt;
    &lt;td width="79" align="center"&gt;&lt;a href="cart.php?addout='.$id.'"&gt;[+]&lt;/a&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;';
                }
            }
        }
    }
}
/////total function///////
///////////////////////// this is my problem ////////////////
// totalin funciotn similar to cart funciont only doing for return the total //////////////
function totalin () {
    foreach($_SESSION as $name =&gt; $value) {
        if ($value &gt;0) {
            if (substr($name, 0, 5)=='cain_') {
                $id = substr($name, 5, (strlen($name)-5));
                $get = mysql_query('SELECT id, inprice FROM cards WHERE id='.mysql_real_escape_string((int)$id));
                while ($get_row = mysql_fetch_assoc($get)){
                    $sub = $get_row['inprice']*$value;
                }
            }
            $total += $sub;
        }
    }
    return $total;
}
//////total out function
function totalout () {
    foreach($_SESSION as $name =&gt; $value) {
        if ($value &gt;0) {
            if (substr($name, 0, 5)=='caou_') {
                $id = substr($name, 5, (strlen($name)-5));
                $get = mysql_query('SELECT id, outprice FROM cards WHERE id='.mysql_real_escape_string((int)$id));
                while ($get_row = mysql_fetch_assoc($get)){
                    $sub = $get_row['outprice']*$value;
                }
            }
            $total += $sub;
        }
    }
    return $total;
}

$balance = totalin () - totalout ();
echo $balance;
</code></pre>

<p>how can i fix my problem? this is my first website so i dont know much more about so please help me guys. please answer with code// please// please//please.</p>
