"Troels Hansen" <idle@invalid.email> skrev i en meddelelse
news:42f649ac$0$18649$14726298@news.sunsite.dk...
> Morten Brøgger wrote:
>
> > ******$sum = $cart ['sum (item_price)'];
>
> Dette duer ikke. Du skal bruge sum allerede i din select.
> Altså noget i retning af:
> $get_cart = "select bla, bla, sum(si.item_price) AS totalpris, bla, bla
from
> store_shoppertrack as st left join store_items as si on si.id =
> st.sel_item_id where session_id = '$PHPSESSID'";
>
> og så i din while løkke udskrive:
> while ($cart = mysql_fetch_array($get_cart_res)) {
> $sum = $cart ['totalpris'];
> osv;
> osv;
> }
Hej Troels
Mange tak for hjælpen.
Men det virker nu stadig ikke. Kommer der ikke et "AS" for meget med i
select linien?
Fejlmeldingen lyder nu: " Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
with no GROUP columns is illegal if there is no GROUP BY clause "
Scriptet ser nu sådan ud:
<?php
session_start();
//connect to database
$conn = mysql_connect("localhost", "***", "***") or die(mysql_error());
mysql_select_db("***",$conn) or die(mysql_error());
$display_block = "<h1>Din bestillingsliste</h1>";
//check for cart items based on user session id
$get_cart = "select sum(si.item_price) as totalpris, st.id, si.item_title,
si.item_price, st.sel_item_id from store_shoppertrack as st left join
store_items as si on si.id = st.sel_item_id where session_id =
'$PHPSESSID'";
$get_cart_res = mysql_query($get_cart) or die(mysql_error());
if (mysql_num_rows($get_cart_res) < 1) {
//print message
$display_block .= "<P>You have no items in your cart.
Please <a href=\"seestore.php\">continue to shop</a>!</p>";
} else {
//get info and build cart display
$display_block .= "
<table celpadding=4 cellspacing=2 border=2 width=90%>
<tr>
<th>Best. nr.</th>
<th>Overskrift</th>
<th>Pris</th>
<th>Slet</th>
</tr>";
while ($cart = mysql_fetch_array($get_cart_res)) {
$sum = $cart ['totalpris'];
$id = $cart['id'];
$item_id = $cart ['sel_item_id'];
$item_title = stripslashes($cart['item_title']);
$item_price = $cart['item_price'];
$display_block .= "<tr>
<td align=center>$item_id <br></td>
<td align=center>$item_title <br></td>
<td align=right>Kr. $item_price <br></td>
<td align=center><a href=\"removefromcart.php?id=$id\">Fjern</a></td>
</tr>";
}
$display_block .= "</table>";
print $sum;
}
?>
<HTML>
<HEAD>
<TITLE>
www.dkfrim.dk - indhold af bestillingsliste</TITLE>
</HEAD>
<BODY>
<? print $display_block; ?>
Venligst <a href="seestore.php">Tilføj flere emner til
bestillingslisten</a>!";</p>
</BODY>
</HTML>
Vil du kigge på det en gang til?
På forhånd tak
--
Med venlig hilsen
Morten Brøgger
www.dkfrim.dk