$NUMROW Help

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
Chinclub
Forum Newbie
Posts: 13
Joined: Sun Aug 31, 2008 7:33 am

$NUMROW Help

Post 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?
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: $NUMROW Help

Post 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
Chinclub
Forum Newbie
Posts: 13
Joined: Sun Aug 31, 2008 7:33 am

Re: $NUMROW Help

Post by Chinclub »

Thank you so much!!
Post Reply