Re: Count Many Records

From: Date: Thu, 29 Jun 2006 00:39:01 +0000
Subject: Re: Count Many Records
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-42129@lists.php.net to get a copy of this message
Kevin Murphy wrote:
Actually the design is in the code below.... I need to display the counts from all of those queries in a grid. Basically, its just a summary of a bunch of information. Another way to look at it would be a several lines that say something like this: You have $data1_count NEW records in data1, You have $data1p_count PROCESSED records in data1, etc.
Instead of $data1_query = "select id from data1 WHERE status = ''"; $data1_results = mysql_query($data1_query); $data1_count = mysql_num_rows($data1_results); $data1p_query = "select id from data1 WHERE status = 'p'"; $data1p_results = mysql_query($data1p_query); $data1p_count = mysql_num_rows($data1p_results); $data1h_query = "select id from data1 WHERE status = 'h'"; $data1h_results = mysql_query($data1h_query); $data1h_count = mysql_num_rows($data1h_results); You could do it all in one query: $query = "select status, count(id) AS count from data1 where status in ('', 'p', 'h') group by status"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo "status: " . $row['status'] . "<br/>"; echo "count: " . $row['count'] . "<br/>"; } -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.db (#42129) next »