0
我要創建一個在線卡交換商店,他們可以購買和出售他們的卡,所以我製作了2個購物車系統。 1用於傳入卡和1用於傳出卡。一切都進展順利接受總數。這裏是我的代碼,請幫助我。我的2個總共r彼此混淆我怎麼能分開他們?
<?php
// cart function for card in
function cardin() {
foreach($_SESSION as $name => $value) {
if ($value >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 '<table align="center" width="900" border="1">
<tr>
<td width="382" align="center">'.$get_row['name'].'</td>
<td width="89" align="center">'.$value.'</td>
<td width="121" align="center">' .$get_row['inprice'].'</td>
<td width="124" align="center">'.$sub.'</td>
<td width="79" align="center"><a href="cart.php?removein='.$id.'">[-]</a></td>
<td width="79" align="center"><a href="cart.php?addin='.$id.'">[+]</a></td>
</tr>
</table>';
}
}
}
}
}
// cart funciotn for out
function cardout() {
foreach($_SESSION as $name => $value) {
if ($value >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 '<table align="center" width="900" border="1">
<tr>
<td width="382" align="center">'.$get_row['name'].'</td>
<td width="89" align="center">'.$value.'</td>
<td width="121" align="center">' .$get_row['outprice'].'</td>
<td width="124" align="center">'.$sub.'</td>
<td width="79" align="center"><a href="cart.php?removeout='.$id.'">[-]</a></td>
<td width="79" align="center"><a href="cart.php?addout='.$id.'">[+]</a></td>
</tr>
</table>';
}
}
}
}
}
/////total function///////
///////////////////////// this is my problem ////////////////
// totalin funciotn similar to cart funciont only doing for return the total //////////////
function totalin() {
foreach($_SESSION as $name => $value) {
if ($value >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 => $value) {
if ($value >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;
我該如何解決我的問題?這是我的第一個網站,所以我不知道更多關於如此請幫助我的人。請用代碼回答//請/ /請/ /請。
請看看我的最後2個功能他們只爲總 – hamp 2011-05-23 11:41:28
R是是我看到他們...在他們兩人,你第一次提到$總變量是在賦值語句中。 – 2011-05-23 11:43:47
$ total是$ subs的數量我的意思是$ total = $ sub + $ sub + $ sub,所以好吧告訴我怎樣才能得到我的2總數thoes功能 – hamp 2011-05-23 11:51:51