Page 1 of 1
check coding
Posted: Thu May 13, 2004 12:34 am
by enefahchen
Y i still can't get total amount?? can check the coding for me????
$sql = "SELECT SUM(SCPrice) AS TotalAmount FROM orderlist WHERE userID ='$username' AND SCDate='$todate' AND Status = 'A'";
$Result = mysql_query($sql,$db);
$row = mysql_fetch_array ($Result);
$totalAmount = $row['TotalAmount'];
Posted: Thu May 13, 2004 7:01 am
by launchcode
What DOES it return? (if anything)
Do you get an SQL error? (although I doubt it, your SQL looks valid to me).
Is there any data in the table for the SUM to work on?! and is the SCPrice column a standard Integer? SUM will only work on numeric fields.
Posted: Thu May 13, 2004 9:48 am
by pickle
Does mysql_fetch_assoc() return an associative array or a number indexed one?
Posted: Thu May 13, 2004 9:57 am
by magicrobotmonkey
mysql_fetch_assoc()
associative array
note: alternativly
mysql_fetch_row($result,ASSOC)
Posted: Thu May 13, 2004 10:04 am
by pickle
Ya, I'm a dumbass. I meant to ask if mysql_fetch_array() returns an associative or numbered array, since that's what ~enefahchen is using. My apologies.

Posted: Thu May 13, 2004 10:15 am
by magicrobotmonkey
mysql_fetch_array($result) returns both
mysql_fetch_array($result, MYSQL_ASSOC) returns associative same as mysql_fetch_assoc($result)
mysql_fetch_array($result, MYSQL_NUM) returns numeric as is mysql_fetch_row($result)
http://us3.php.net/manual/en/function.m ... -array.php
Posted: Thu May 13, 2004 10:28 am
by pickle
So mysql_fetch_array returns both an associative array and a numeric array? So the way ~enefahchen is using it should work. Ok.
Posted: Thu May 13, 2004 10:31 am
by magicrobotmonkey
use print_r() to check it out. I find that if I play with arrays with this it helps me uinderstand the code a lot better because i can see the array