Page 1 of 1

$NUMROW Help

Posted: Wed Sep 03, 2008 4:10 pm
by Chinclub
Ok, Again this is probably an obvious error I am missing here (newbie that I am)....

I am trying to get the code to count the number of items of a given member and multiply that number by 4 and give a total.

This is the code I have:

Code: Select all

$NUMROWS = mysql_query("select count(*) from items WHERE `user`='user'");
$cost = $NUMROWS * 4;
print " $cost";

It keeps showing $cost as 44 no matter how many items there actually are in the database. :banghead: What am I doing wrong?

Re: $NUMROW Help

Posted: Wed Sep 03, 2008 4:14 pm
by andyhoneycutt
What you're actually multiplying by 4 is the result set itself. You need to pull information from the result to accomplish what you're setting out to do:

Code: Select all

$query = "SELECT COUNT(*) AS c FROM items WHERE `user`='user'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$cost = $row['c'] * 4;
print " $cost";
-Andy

Re: $NUMROW Help

Posted: Wed Sep 03, 2008 4:17 pm
by Chinclub
Thank you so much!!