Jump to content

Double query


djp1988

Recommended Posts

I need to retreive the number of users who have contributed to the site, I have a table 'herpers' and a table 'trips'There are some herpers that have not contributed a trip

<?php require_once ('mysql_connect.php');$query = 'SELECT COUNT(user_id) AS totalmembers FROM users';$result = mysql_query ($query, $dbc);$row = mysql_fetch_array ($result, MYSQL_BOTH);echo"Total Members: <b>{$row['totalmembers']}</b><br />"; $query = 'SELECT COUNT(id_trip) AS totaltrips FROM trips';$result = mysql_query ($query, $dbc);$row = mysql_fetch_array ($result, MYSQL_BOTH);echo"Total Field reports: <b>{$row['totaltrips']}</b><br />"; // HERE IS THE PROBLEM:$query = 'SELECT COUNT(herper_id) AS contributors FROM trips GROUP BY herper_id'; //gives me 4 rows$result = mysql_query ($query, $dbc);$query2 = 'SELECT COUNT(contributors) AS TOT'; // counts the 4 rows$result2 = mysql_query ($query2, $dbc);$row = mysql_fetch_array ($result2, MYSQL_BOTH);echo"Total Contributors: <b>{$row['TOT']}</b><br />";  //should echo "4" ??? but doesn't work?>

If I

SELECT COUNT(herper_id) AS contibut FROM trips GROUP BY herper_id

I get 4 rows,If I

SELECT COUNT(herper_id) AS contibut FROM trips

I get "9" as a result (because there have been 9 contributions from 4 people)Can someone help me get the number 4 !!! ???Here are my tables:TRIPS(id_trip, country_id, trip_name, herper_id)HERPERS(id_herper, herper_name)Is there a way to SQL the result of a SQL ?Thank you

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...