check coding

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!

Moderator: General Moderators

Post Reply
enefahchen
Forum Newbie
Posts: 10
Joined: Wed May 12, 2004 1:35 am

check coding

Post 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'];
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Does mysql_fetch_assoc() return an associative array or a number indexed one?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

mysql_fetch_assoc()

associative array

note: alternativly

mysql_fetch_row($result,ASSOC)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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. :oops:
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post 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
Post Reply