vomitbomb Posted May 11, 2008 Share Posted May 11, 2008 Hey there, I'm putting together an ordering system and at certain points in the system the user wants to see how many of a particular item has been ordered so they can have the correct amount of stock. Any thoughts on how to do this? Link to comment https://forums.phpfreaks.com/topic/105116-solved-adding-up-a-specific-entry-in-a-database-mysql/ Share on other sites More sharing options...
MasterACE14 Posted May 11, 2008 Share Posted May 11, 2008 give this a try <?php // grab the info from the database $query = mysql_query("SELECT * FROM `table` WHERE `userid`='23' ") or die("Problem with query"); // grab all the columns in the table $row = mysql_fetch_array($query); // count how many items are in the table $items = mysql_num_rows($query); // display the items echo $row['itemname'] . "<br>"; echo "<hr>"; // display the amount of items echo $items; ?> Regards ACE Link to comment https://forums.phpfreaks.com/topic/105116-solved-adding-up-a-specific-entry-in-a-database-mysql/#findComment-538185 Share on other sites More sharing options...
vomitbomb Posted May 11, 2008 Author Share Posted May 11, 2008 Some entries may have say 15 and others may have 1, I'm not looking at how many entries there is, but the sum of all the entry values added up in a certain COLUMN.. Will this do that? (sorry I'm just learning) example: Say I want the sum of all the GREEN values which is 34. Will that code do it for me? id blue yellow green 0 5 3 9 1 2 3 3 2 7 2 6 3 9 1 7 4 1 4 7 5 6 6 2 Link to comment https://forums.phpfreaks.com/topic/105116-solved-adding-up-a-specific-entry-in-a-database-mysql/#findComment-538195 Share on other sites More sharing options...
MasterACE14 Posted May 11, 2008 Share Posted May 11, 2008 whats the current code you have? and hows the table set up in the database? Link to comment https://forums.phpfreaks.com/topic/105116-solved-adding-up-a-specific-entry-in-a-database-mysql/#findComment-538197 Share on other sites More sharing options...
vomitbomb Posted May 11, 2008 Author Share Posted May 11, 2008 I haven't started the php yet, just trying to get idea's on how it's all going to work. I put an example in the post above so I hope what I'm asking makes more sense now. Ok I've just realised I meant COLUMN not row, sorry. Link to comment https://forums.phpfreaks.com/topic/105116-solved-adding-up-a-specific-entry-in-a-database-mysql/#findComment-538198 Share on other sites More sharing options...
vomitbomb Posted May 12, 2008 Author Share Posted May 12, 2008 Any idea's on this one? Link to comment https://forums.phpfreaks.com/topic/105116-solved-adding-up-a-specific-entry-in-a-database-mysql/#findComment-538887 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.