Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to: Pull out values for a field as well as a count() with PHP

Status
Not open for further replies.

jmreinwald

Technical User
Jun 3, 2002
46
US
Hi folsk,

I'm relatively new to the world of PHP/MySQL. For a simple real-world scenario, I have a pretty simple db created to track some hockey trading cards. For simplicity, I have it set up as follows:
set_name (year and set name)
player_name
number
quantity
box (this is the box I have it stored in)

Ultimately what I want to do is pull a list of DISTINCT Set names and a total Quantity for all cards from a particular Location. In the client, the select statement I have for testing is:
Code:
select distinct set_name,count(quantity) from tblmaster where box = 'a' GROUP BY set_name;

The output looks fine, but I don't know how to grab the total quantity value for PHP. I know the set_name is accessible through
Code:
while ($row = mysql_fetch_array($result)) {
	$set_name = $row['set_name'];
...}
but how do I get the total count for any set?
 
give your count(quantity) a name, and refer to it by that name, like this

Code:
select distinct set_name,count(quantity) as mytotal from tblmaster where box = 'a' GROUP BY set_name;

while ($row = mysql_fetch_array($result)) {
$total = $row['mytotal'];
...}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top