Re: [PHP-DB] COUNT and OUTER JOIN results

2011-05-06 Thread Ron Piggott
thank you for explaining this to me Amit.  It works.  Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info  


From: Amit Tandon 
Sent: Friday, May 06, 2011 5:49 AM
To: Ron Piggott 
Cc: php-db@lists.php.net 
Subject: Re: [PHP-DB] COUNT and OUTER JOIN results

Dear Ron

Take your condition to ON cluause. So your on clause (for LEFT JOIN) would read 
something like

ON `prayer_request_category`.` 
reference` = `prayer_requests`.`prayer_request_category_reference`
AND 

`prayer_requests`.`approval_ 
level` IN ( 1, 3 )
`prayer_requests`.`prayer_request_type` = 1





regds
amit

"The difference between fiction and reality? Fiction has to make sense."



On Fri, May 6, 2011 at 2:42 PM, Ron Piggott  
wrote:

  The following query returns all 8 prayer request categories with the total # 
of requests every submitted to each category:

  SELECT `prayer_request_category`.`reference` , 
`prayer_request_category`.`category` , COUNT( `prayer_requests`.`reference` ) 
AS category_request_count
  FROM `prayer_request_category`
  LEFT OUTER JOIN `prayer_requests` ON `prayer_request_category`.`reference` = 
`prayer_requests`.`prayer_request_category_reference`
  GROUP BY `prayer_request_category`.`reference`
  ORDER BY `prayer_request_category`.`category` ASC

  I would like to add the following 2 WHERE conditions to this query so only 
the live prayer requests are included in the COUNT:

  `prayer_requests`.`approval_level` IN ( 1, 3 )
  `prayer_requests`.`prayer_request_type` = 1

  When I do this only the categories with live prayer requests are returned, 
instead of all 8 categories.  Is there a way to build these WHERE conditions 
which will still allow all 8 categories to be included in the result?
  Thank you,

  Ron

  The Verse of the Day
  “Encouragement from God’s Word”
  http://www.TheVerseOfTheDay.info 

  -- 
  PHP Database Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] COUNT and OUTER JOIN results

2011-05-06 Thread Amit Tandon
Dear Ron

Take your condition to ON cluause. So your on clause (for LEFT JOIN) would
read something like

ON `prayer_request_category`.`
reference` = `prayer_requests`.`prayer_request_category_reference`
AND

`prayer_requests`.`approval_
level` IN ( 1, 3 )
`prayer_requests`.`prayer_request_type` = 1




regds
amit

"The difference between fiction and reality? Fiction has to make sense."


On Fri, May 6, 2011 at 2:42 PM, Ron Piggott
wrote:

> The following query returns all 8 prayer request categories with the total
> # of requests every submitted to each category:
>
> SELECT `prayer_request_category`.`reference` ,
> `prayer_request_category`.`category` , COUNT( `prayer_requests`.`reference`
> ) AS category_request_count
> FROM `prayer_request_category`
> LEFT OUTER JOIN `prayer_requests` ON `prayer_request_category`.`reference`
> = `prayer_requests`.`prayer_request_category_reference`
> GROUP BY `prayer_request_category`.`reference`
> ORDER BY `prayer_request_category`.`category` ASC
>
> I would like to add the following 2 WHERE conditions to this query so only
> the live prayer requests are included in the COUNT:
>
> `prayer_requests`.`approval_level` IN ( 1, 3 )
> `prayer_requests`.`prayer_request_type` = 1
>
> When I do this only the categories with live prayer requests are returned,
> instead of all 8 categories.  Is there a way to build these WHERE conditions
> which will still allow all 8 categories to be included in the result?
> Thank you,
>
> Ron
>
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


[PHP-DB] COUNT and OUTER JOIN results

2011-05-06 Thread Ron Piggott
The following query returns all 8 prayer request categories with the total # 
of requests every submitted to each category:


SELECT `prayer_request_category`.`reference` , 
`prayer_request_category`.`category` , COUNT( 
`prayer_requests`.`reference` ) AS category_request_count

FROM `prayer_request_category`
LEFT OUTER JOIN `prayer_requests` ON `prayer_request_category`.`reference` = 
`prayer_requests`.`prayer_request_category_reference`

GROUP BY `prayer_request_category`.`reference`
ORDER BY `prayer_request_category`.`category` ASC

I would like to add the following 2 WHERE conditions to this query so only 
the live prayer requests are included in the COUNT:


`prayer_requests`.`approval_level` IN ( 1, 3 )
`prayer_requests`.`prayer_request_type` = 1

When I do this only the categories with live prayer requests are returned, 
instead of all 8 categories.  Is there a way to build these WHERE conditions 
which will still allow all 8 categories to be included in the result?

Thank you,

Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info 



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] COUNT() query help

2010-08-13 Thread Richard Quadling
On 13 August 2010 13:43, Ron Piggott  wrote:
> SELECT `bible_concordance_words`.`reference`,
> `bible_concordance_words`.`word`,
> COUNT(`bible_concordance_word_reference`.`bible_concordance_words_reference`)
> AS occurrences FROM `bible_concordance_words` INNER JOIN
> `bible_concordance_word_reference` ON
> `bible_concordance_words`.`reference` =
> `bible_concordance_word_reference`.`bible_concordance_words_reference`
> WHERE `word` LIKE '$letter%' ORDER BY `word` ASC

SELECT
`bible_concordance_words`.`word`,

COUNT(`bible_concordance_word_reference`.`bible_concordance_words_reference`)
AS occurrences
FROM
`bible_concordance_words`
INNER JOIN
`bible_concordance_word_reference` ON
`bible_concordance_words`.`reference` =
`bible_concordance_word_reference`.`bible_concordance_words_reference`
WHERE
`word` LIKE '$letter%'
GROUP BY
`bible_concordance_words`.`word`,
ORDER BY
`word` ASC

-- 
Richard Quadling.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] COUNT() query help

2010-08-13 Thread Ron Piggott
I am making a Bible concordance.  I need help with the query that figures
out how many times each word is in the Bible.

The COUNT() in the query below is giving me the total number of words for
the letter of the alphabet, not the specific word, and is causing there to
be only 1 search result.

I have 2 tables for the concordance.  I have a "words" table and I have a
table that records the words each verse of the Bible contains.

The common field between both tables is:

`bible_concordance_words`.`reference`

equals:

`bible_concordance_word_reference`.`bible_concordance_words_reference`

This is the query so far.  What change do I need to make so COUNT() will
tell me the number of times a word is used in the Bible with the design of
my tables?

SELECT `bible_concordance_words`.`reference`,
`bible_concordance_words`.`word`,
COUNT(`bible_concordance_word_reference`.`bible_concordance_words_reference`)
AS occurrences FROM `bible_concordance_words` INNER JOIN
`bible_concordance_word_reference` ON
`bible_concordance_words`.`reference` =
`bible_concordance_word_reference`.`bible_concordance_words_reference`
WHERE `word` LIKE '$letter%' ORDER BY `word` ASC

Thanks for your help.

Ron


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] "COUNT() returns 0 if there were no matching rows." .... really?!

2009-08-06 Thread Govinda

Hi all

I am 99.9% sure it is my lack of understanding something, but it sure  
seems like my PHP/MySQL code is returning something other than what i  
expect from reading the docs.


to explain:
this code is serving me (almost perfectly) well:

---
$query = "SELECT COUNT(*) AS `CountRowsThisDateThisTBL`,  
date(solarLandingDateTime) AS `uniqueDate`, 't7solar_landing' AS  
`tableAlias` FROM t7solar_landing GROUP BY date(solarLandingDateTime)  
UNION ALL SELECT count(*) AS `CountRowsThisDateThisTBL`,  
date(solarAweberConfDateTime) AS `uniqueDate`, 'aweber_7solar_confirm'  
AS `tableAlias` FROM aweber_7solar_confirm GROUP BY  
date(solarAweberConfDateTime) UNION ALL SELECT count(*) AS  
`CountRowsThisDateThisTBL`, date(solarAWDateTime) AS `uniqueDate`,  
'aweber_7solar_aw' AS `tableAlias` FROM aweber_7solar_aw GROUP BY  
date(solarAWDateTime) ORDER BY uniqueDate DESC LIMIT 300";


$foundUniqueDateROWS = mysql_query($query) or die("query failed:  
" .mysql_error());

while ($uniqueDateROW = mysql_fetch_object($foundUniqueDateROWS)) {

$CountRowsThisDateThisTBL=0;

$uniqueDate=htmlentities($uniqueDateROW->uniqueDate);
$tableAlias=htmlentities($uniqueDateROW->tableAlias);
	$CountRowsThisDateThisTBL=htmlentities($uniqueDateROW- 
>CountRowsThisDateThisTBL);


$TBLsubarray["$uniqueDateROW->tableAlias"]=$CountRowsThisDateThisTBL;
$BuildPerUniqueDateArray[$uniqueDateROW->uniqueDate]=$TBLsubarray;
}
---

...but I am having the problem, that on iterations of the while loop  
where there are NO records in one of those tables on a particular date  
(when the *other* tables *do* have records for that date), then the  
variable $CountRowsThisDateThisTBL seems to persist its previous value  
(from what it was on the last iteration for the same table (previous  
date, same table), as opposed to what I would expect (that it should  
be set to "0" since count() should be returning "0" for this iteration.


What am I missing?

Here's an example (snip) from a var_dump of that  
$BuildPerUniqueDateArray:
(note that the 'aweber_7solar_aw' table does NOT have a record for the  
date '2009-07-28', so I would expect to see that "1" to be a "0" there.)

["2009-07-29"]=>
  array(3) {
["aweber_7solar_aw"]=>
string(1) "1"
["t7solar_landing"]=>
string(1) "1"
["aweber_7solar_confirm"]=>
string(1) "1"
  }
  ["2009-07-28"]=>
  array(3) {
["aweber_7solar_aw"]=>
string(1) "1"
["t7solar_landing"]=>
string(1) "5"
["aweber_7solar_confirm"]=>
string(1) "2"

thanks,
-Govinda

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Count Many Records

2006-06-29 Thread Kevin Murphy
Thanks for your help, Chris. You certainly got me going in the right  
direction. In case anyone is interested, below is the completed  
solution, with design elements, turned into a function so I can  
easily call it several times.


function counter_maker ($database,$name,$link)
{   
echo "";
		echo "\"content\">$name";


		$query = "select status, count(id) AS count from $database where  
status in ('', 'h', 'p') group by status";

$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{   
$status_code = $row['status'];
if ($status_code == "")
{   $status_code = "n";   }
$count_array[$status_code] = $row['count'];
}
echo "		{	echo " style=\"background-color: #F3CF45; color: #00599E; font- 
weight: bold;\">";

echo $count_array['n']; }
else
{   echo "> 0";}
echo "";
echo "		{	echo " style=\"background-color: #00599E; color: #F3CF45; font- 
weight: bold;\">";

echo $count_array['h']; }
else
{   echo "> 0";}
echo "";
echo "";
if (isset($count_array['p']))
{   echo $count_array['p']; }
else
{   echo "0"; }
echo "";
}


counter_maker ("data1","Form Name","link.php");



--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On Jun 28, 2006, at 5:39 PM, Chris wrote:


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'] . "";
  echo "count: " . $row['count'] . "";
}

--
Postgresql & php tutorials
http://www.designmagick.com/




Re: [PHP-DB] Count Many Records

2006-06-28 Thread Chris

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'] . "";
  echo "count: " . $row['count'] . "";
}

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Count Many Records

2006-06-28 Thread Kevin Murphy
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.

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On Jun 28, 2006, at 1:56 PM, [EMAIL PROTECTED] wrote:




Kevin Murphy asks:
The following code works and accomplishes what I need it to do, but I
am wondering if there is a better way to accomplish the same task. I
have several tables of records and I need to count and then display.
Even if I could just combine the first three queries (below) into one
that would probably be a lot better than what I am doing now.

   $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);

   echo "";
   echo "$data1_counttd>";
   echo " 
$data1h_count";
   echo " 
$data1p_count";

   echo "";

Then do the same thing for the second table, and so on.

   $data2_query = "select id from data2 WHERE status = ''";
   $data2_results = mysql_query($data2_query);
   $data2_count = mysql_num_rows($data2_results);

   $data2p_query = "select id from data2 WHERE status = 'p'";
   $data2p_results = mysql_query($data2p_query);
   $data2p_count = mysql_num_rows($data2p_results);

   $data2h_query = "select id from data2 WHERE status = 'h'";
   $data2h_results = mysql_query($data2h_query);
   $data2h_count = mysql_num_rows($data2h_results);

   echo "";
   echo "$data2_counttd>";
   echo " 
$data2h_count";
   echo " 
$data2p_count";

   echo "";


Kevin,

You haven't said what you want the page to look like, but you could  
have a

html select box of "letters" (a,b,c,d...) that would allow for the
selection of multiple items, then grab the values out of the array  
created

and add them to the select query, and loop through it:
$data1_query = "select id from data1 WHERE status
= '$value_from_letter_array'";
Then process as you have done.

Or you could use a checkbox array...

Does that help any?

David






Re: [PHP-DB] Count Many Records

2006-06-28 Thread dpgirago

> Kevin Murphy asks:
> The following code works and accomplishes what I need it to do, but I
> am wondering if there is a better way to accomplish the same task. I
> have several tables of records and I need to count and then display.
> Even if I could just combine the first three queries (below) into one
> that would probably be a lot better than what I am doing now.
>
>$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);
>
>echo "";
>echo "$data1_count";
>echo "$data1h_count";
>echo "$data1p_count";
>echo "";
>
> Then do the same thing for the second table, and so on.
>
>$data2_query = "select id from data2 WHERE status = ''";
>$data2_results = mysql_query($data2_query);
>$data2_count = mysql_num_rows($data2_results);
>
>$data2p_query = "select id from data2 WHERE status = 'p'";
>$data2p_results = mysql_query($data2p_query);
>$data2p_count = mysql_num_rows($data2p_results);
>
>$data2h_query = "select id from data2 WHERE status = 'h'";
>$data2h_results = mysql_query($data2h_query);
>$data2h_count = mysql_num_rows($data2h_results);
>
>echo "";
>echo "$data2_count";
>echo "$data2h_count";
>echo "$data2p_count";
>echo "";

Kevin,

You haven't said what you want the page to look like, but you could have a
html select box of "letters" (a,b,c,d...) that would allow for the
selection of multiple items, then grab the values out of the array created
and add them to the select query, and loop through it:
$data1_query = "select id from data1 WHERE status
= '$value_from_letter_array'";
Then process as you have done.

Or you could use a checkbox array...

Does that help any?

David

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Count Many Records

2006-06-28 Thread Kevin Murphy
Thanks in advance for your help, and forgive me if this is me being  
bone-headed. :-)


The following code works and accomplishes what I need it to do, but I  
am wondering if there is a better way to accomplish the same task. I  
have several tables of records and I need to count and then display.  
Even if I could just combine the first three queries (below) into one  
that would probably be a lot better than what I am doing now.


$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);

echo "";
echo "$data1_count";
echo "$data1h_count";
echo "$data1p_count";
echo "";

Then do the same thing for the second table, and so on.

$data2_query = "select id from data2 WHERE status = ''";
$data2_results = mysql_query($data2_query);
$data2_count = mysql_num_rows($data2_results);

$data2p_query = "select id from data2 WHERE status = 'p'";
$data2p_results = mysql_query($data2p_query);
$data2p_count = mysql_num_rows($data2p_results);

$data2h_query = "select id from data2 WHERE status = 'h'";
$data2h_results = mysql_query($data2h_query);
$data2h_count = mysql_num_rows($data2h_results);

echo "";
echo "$data2_count";
echo "$data2h_count";
echo "$data2p_count";
echo "";

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326



--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326




Re: [PHP-DB] Count unique visits in PHP/MySQL

2004-06-08 Thread Ignatius Reilly
Here is how I would do:

1. Group your visits by IP, order them in time and give each row a
sequential number starting with 1
(not completely trivial - exercise left to the reader)

Now you have a temporary table T ( ip, timestamp, rank )

2. Join the table to itself on two consecutive rows, and compute the
timestamp difference between the rows
(actually you must create a replica of the table because you can not
self-join a temporary table)

SELECT
ip,
SUM(
IF(
UNIX_TIMESTAMP( T.timestamp ) - UNIX_TIMESTAMP( U.timestamp ) <=
60*30
0,
1
)
) AS unik_visits
FROM T
LEFT JOIN U
ONU.ip = T.ip
AND  U.rank = T.rank + 1
GROUP BY ip

HTH
Ignatius
_
- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 08, 2004 5:03 PM
Subject: [PHP-DB] Count unique visits in PHP/MySQL


> I am making a PHP/MySQL traffic report page from a table that records some
user activity using PHP referrer information.
>
> I have a table with three rows: IP, page_name, and timestamp. The IP row
records the user's IP address, page_name records the name of the page that
the user loaded, and the timestamp row records in Unix timestamp format the
time of day that the user requested the page.
>
> I want to be able to count unique visits per IP according to Internet
Advertising Bureau standards, which count a "Unique Visit" as a log in by
the same IP once every thirty minutes.
>
> IAB verbatim definition: "Visit - One or more text and/or graphics
downloads from a site qualifying as at least one page, without 30
consecutive minutes of inactivity, which can be reasonably attributed to a
single browser for a single session. A browser must "pull" text or graphics
content to be considered a visit."
>
> So I need to make a MySQL query that will count how many times an IP
logged a timestamp within a given time period.
>
> For example, the publisher checking traffic could request a date between
May 1 and May 31, and I'd like to be able to return a page that counted
unique users (count distinct IP), pages viewed (list distinct pages) and how
many times they visited in that period. I have the first two down, but not
the unique visits. Any ideas?
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Count unique visits in PHP/MySQL

2004-06-08 Thread veditio
I am making a PHP/MySQL traffic report page from a table that records some user 
activity using PHP referrer information.

I have a table with three rows: IP, page_name, and timestamp. The IP row records the 
user's IP address, page_name records the name of the page that the user loaded, and 
the timestamp row records in Unix timestamp format the time of day that the user 
requested the page.

I want to be able to count unique visits per IP according to Internet Advertising 
Bureau standards, which count a "Unique Visit" as a log in by the same IP once every 
thirty minutes.

IAB verbatim definition: "Visit – One or more text and/or graphics downloads from a 
site qualifying as at least one page, without 30 consecutive minutes of inactivity, 
which can be reasonably attributed to a single browser for a single session. A browser 
must “pull” text or graphics content to be considered a visit."

So I need to make a MySQL query that will count how many times an IP logged a 
timestamp within a given time period.

For example, the publisher checking traffic could request a date between May 1 and May 
31, and I'd like to be able to return a page that counted unique users (count distinct 
IP), pages viewed (list distinct pages) and how many times they visited in that 
period. I have the first two down, but not the unique visits. Any ideas?

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] COUNT() returns 1, but should be 0

2003-12-21 Thread Lew Mark-Andrews
John,

>That's because you're displaying how many "rows" were returned from the
>query, not the value that COUNT() returns. A query with COUNT() is
>always going to return at least one row.
>
>$visitcount = mysql_result($query,0);

Yes, that was it! Thank you so much.

Lew

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] COUNT() returns 1, but should be 0

2003-12-21 Thread John W. Holmes
Lew Mark-Andrews wrote:

I get a count of 1 for the number of visits
($visitcount) using my following code. It should be 0. 
---
 code in check_visits.php
$sql = "SELECT COUNT(visitdate) FROM cardlist GROUP BY visitdate";
$query = mysql_query($sql) or die(" Cannot
query the database." .  "MySQL Error No. " . mysql_errno() . " :
" . mysql_error() . "");
$visitcount = mysql_num_rows($query);
[snip]
echo "Total number of users: $usercount";
echo "Total number of visits: $visitcount"; // <--- Should be zero.

That's because you're displaying how many "rows" were returned from the 
query, not the value that COUNT() returns. A query with COUNT() is 
always going to return at least one row.

$visitcount = mysql_result($query,0);

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] COUNT() returns 1, but should be 0

2003-12-21 Thread Tobey Wheelock
On Mon, Dec 22, 2003 at 11:43:35AM +0900, Lew Mark-Andrews wrote:
> Table structure for cardlist:
>   `visitdate` datetime default NULL,

> $sql = "SELECT COUNT(visitdate) FROM cardlist GROUP BY visitdate";

> $visitcount = mysql_num_rows($query);

> echo "Total number of visits: $visitcount"; // <--- Should be zero.


I think that there is one visitdate (NULL), so one row is returned.

HTH,
Tobey Wheelock

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] COUNT() returns 1, but should be 0

2003-12-21 Thread Lew Mark-Andrews
Hi all,

I'm baffled by this. I've put together a rather simple newsletter +
greeting card app for a company to send their clients personalized
corporate e-mails each containing the URL link to the greeting card page.
When the user successfully visits the view card page, my code writes the
visit date to the cardlist db (MySQL). One of the admin pages
(check_visits.php) lets the admin view a table listing of all the user
names, email addresses, card sent date and card seen date. Above this table
I display the total number of users and the total number of visits.
Presently, the table has only 160 records. No cards have been sent yet and
thus no visits, but I get a count of 1 for the number of visits
($visitcount) using my following code. It should be 0. The number of users
($usercount) is returned correctly at 160.
Any ideas/advice would be much appreciated.

Thanks,
Lew
---
MySQL: 3.23.54
PHP: 4.3.1
Linux
---
Table structure for cardlist:
  `custid` int(10) unsigned NOT NULL auto_increment,
  `fullname` varchar(100) NOT NULL default '',
  `email` varchar(100) NOT NULL default '',
  `cardid` varchar(12) NOT NULL default '0',
  `sentdate` datetime default NULL,
  `visitdate` datetime default NULL,
  PRIMARY KEY  (`custid`),
  UNIQUE KEY `email` (`email`)
---
 code in check_visits.php
$sql = "SELECT COUNT(visitdate) FROM cardlist GROUP BY visitdate";
$query = mysql_query($sql) or die(" Cannot
query the database." .  "MySQL Error No. " . mysql_errno() . " :
" . mysql_error() . "");
$visitcount = mysql_num_rows($query);

$sql = "SELECT * FROM cardlist";
$query = mysql_query($sql) or die(" Cannot
query the database." .  "MySQL Error No. " . mysql_errno() . " :
" . mysql_error() . "");
$usercount = mysql_num_rows($query);

echo "Total number of users: $usercount";
echo "Total number of visits: $visitcount"; // <--- Should be zero.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Count down

2003-09-22 Thread Peter Beckman
On Mon, 22 Sep 2003, Peter Beckman wrote:

> On Mon, 22 Sep 2003, Frank McIsaac wrote:
>
> > Hi all.  I was wanting to make a page that takes a set date and
> > counts down to zero displaying days, minutes, and seconds.  Basically, I
> > want it to count down from the current date and time until a future date
> > and time is reached (ie.  Sept. 30th is x days, y minutes, and z seconds
> > away from right now).  Is this possible?  If so, how.  Thanks for the
> > help.
>
>  $futuretime = strtotime("9/30/2003 12:00:00");
>
>  $difftime = $futuretime - time();
>
>  $days = (int)($difftime/86400);
>  $leftover = $difftime%86400;
>  $minutes = (int)($leftover/1440);
>  $leftover = $leftover%1440;

 Whoops.  Change 1440 to 60 in the above two lines.

>  $seconds = $leftover;
>
>  printf("Future Time is %d day%s, %d minute%s, and %d second%s away from
>  now.", $days, $days==1?"":"s",
> $minutes, $minutes==1?"":"s",
> $seconds, $seconds==1?"":"s");

Beckman
---
Peter Beckman  Internet Guy
[EMAIL PROTECTED] http://www.purplecow.com/
---

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Count down

2003-09-22 Thread Peter Beckman
On Mon, 22 Sep 2003, Frank McIsaac wrote:

> Hi all.  I was wanting to make a page that takes a set date and
> counts down to zero displaying days, minutes, and seconds.  Basically, I
> want it to count down from the current date and time until a future date
> and time is reached (ie.  Sept. 30th is x days, y minutes, and z seconds
> away from right now).  Is this possible?  If so, how.  Thanks for the
> help.

 $futuretime = strtotime("9/30/2003 12:00:00");

 $difftime = $futuretime - time();

 $days = (int)($difftime/86400);
 $leftover = $difftime%86400;
 $minutes = (int)($leftover/1440);
 $leftover = $leftover%1440;
 $seconds = $leftover;

 printf("Future Time is %d day%s, %d minute%s, and %d second%s away from
 now.", $days, $days==1?"":"s",
$minutes, $minutes==1?"":"s",
$seconds, $seconds==1?"":"s");

Beckman
---
Peter Beckman  Internet Guy
[EMAIL PROTECTED] http://www.purplecow.com/
- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-DB] Count down

2003-09-22 Thread Frank McIsaac
Hi all.  I was wanting to make a page that takes a set date and
counts down to zero displaying days, minutes, and seconds.  Basically, I
want it to count down from the current date and time until a future date
and time is reached (ie.  Sept. 30th is x days, y minutes, and z seconds
away from right now).  Is this possible?  If so, how.  Thanks for the
help.

Frank

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DB] COUNT & AVG

2003-09-05 Thread John W. Holmes
Shaun wrote:

Is it possible to combine the COUNT & AVG functions using MySQL? I have a
table called Bookings and I need to find out the average number of bookings.
So I need to count the number of bookings in the table and then get the
Average, is this possible?
Learn SQL, please.

SELECT COUNT(column), AVG(column) FROM table GROUP BY column

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] COUNT & AVG

2003-09-05 Thread Shaun
Hi,

Is it possible to combine the COUNT & AVG functions using MySQL? I have a
table called Bookings and I need to find out the average number of bookings.
So I need to count the number of bookings in the table and then get the
Average, is this possible?

Thanks for your help

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Count database-values

2003-06-10 Thread Becoming Digital
I love when things go completely over my head for no apparent reason.  I have an
incredible talent for missing the obvious.

Edward Dudlik
Becoming Digital
www.becomingdigital.com


- Original Message -
From: "Hutchins, Richard" <[EMAIL PROTECTED]>
To: "'Becoming Digital'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, 10 June, 2003 13:14
Subject: RE: [PHP-DB] Count database-values


Edward,

Have you considered trying mysql_result()?

It appears that your query is going to always return a single piece of data:
Total. So you essentially have an array with only a single element. If you
did this:

$total = mysql_result($result,0);

You'll get the value of the item at index 0 (the first position in an array)
of the $result array stored in the $total variable.

Details are here:
http://us3.php.net/manual/en/function.mysql-result.php

The page also makes reference to other "high-performance" options, but since
you're only grabbing a single item and if you use the index number instead
of the column name as the documentation recommends, the performance should
be just fine.

Hope this helps.

Rich

> -Original Message-
> From: Becoming Digital [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, June 10, 2003 12:50 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Count database-values
>
>
> Unfortunately, I can't, despite my best efforts, get the data
> to display unless
> it's put inside a loop.  If anyone can tell me how to, I'd
> just for joy.
>
> Edward Dudlik
> Becoming Digital
> www.becomingdigital.com
>
>
> - Original Message -
> From: "Ford, Mike [LSS]" <[EMAIL PROTECTED]>
> To: "'Becoming Digital'" <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Sent: Tuesday, 10 June, 2003 11:54
> Subject: RE: [PHP-DB] Count database-values
>
>
> > -Original Message-
> > From: Becoming Digital [mailto:[EMAIL PROTECTED]
> > Sent: 10 June 2003 12:15
> >
> > I screwed up my own code.  Silly me.  It should read:
>
> Surely your first attempt is the right one?  There's only
> ever going to be 1
> Total, so why waste a while loop trying to read more than one
> result row?
>
> > $query = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> > posneg = 'af'";
> > $result = mysql_query( $query );
> > while ( $total = mysql_fetch_array( $result ) )
> > {
> > $total = $total['Total'];
> > }
> >
> > Edward Dudlik
> > Becoming Digital
> > www.becomingdigital.com
> >
> >
> > - Original Message -
> > From: "Becoming Digital" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Tuesday, 10 June, 2003 06:43
> > Subject: Re: [PHP-DB] Count database-values
> >
> >
> > > So far no problems, but I want to count all these values.
> > > I tried with SUM but with the following code it doesn't work:
> > >
> > > $squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> > posneg = 'af'";
> > >
> > > any suggestions how to do? I want to store it in a
> > variabele ($total)
> > > so I can echo it. (E.g.: $total = 93.63 in this case)
> >
> > If you want the total, you need to do something like the following:
> >
> > $query = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> > posneg = 'af'";
> > $result = mysql_query( $query );
> > $total = mysql_fetch_array( $result );
> > $total = $total['Total'];
> >
>
> Cheers!
>
> Mike
>
> -
> Mike Ford,  Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
> Email: [EMAIL PROTECTED]
> Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Count database-values

2003-06-10 Thread Hutchins, Richard
Edward,

Have you considered trying mysql_result()?

It appears that your query is going to always return a single piece of data:
Total. So you essentially have an array with only a single element. If you
did this:

$total = mysql_result($result,0);

You'll get the value of the item at index 0 (the first position in an array)
of the $result array stored in the $total variable.

Details are here:
http://us3.php.net/manual/en/function.mysql-result.php

The page also makes reference to other "high-performance" options, but since
you're only grabbing a single item and if you use the index number instead
of the column name as the documentation recommends, the performance should
be just fine.

Hope this helps.

Rich

> -Original Message-
> From: Becoming Digital [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, June 10, 2003 12:50 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Count database-values
> 
> 
> Unfortunately, I can't, despite my best efforts, get the data 
> to display unless
> it's put inside a loop.  If anyone can tell me how to, I'd 
> just for joy.
> 
> Edward Dudlik
> Becoming Digital
> www.becomingdigital.com
> 
> 
> - Original Message -
> From: "Ford, Mike [LSS]" <[EMAIL PROTECTED]>
> To: "'Becoming Digital'" <[EMAIL PROTECTED]>; 
> <[EMAIL PROTECTED]>
> Sent: Tuesday, 10 June, 2003 11:54
> Subject: RE: [PHP-DB] Count database-values
> 
> 
> > -Original Message-
> > From: Becoming Digital [mailto:[EMAIL PROTECTED]
> > Sent: 10 June 2003 12:15
> >
> > I screwed up my own code.  Silly me.  It should read:
> 
> Surely your first attempt is the right one?  There's only 
> ever going to be 1
> Total, so why waste a while loop trying to read more than one 
> result row?
> 
> > $query = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> > posneg = 'af'";
> > $result = mysql_query( $query );
> > while ( $total = mysql_fetch_array( $result ) )
> > {
> > $total = $total['Total'];
> > }
> >
> > Edward Dudlik
> > Becoming Digital
> > www.becomingdigital.com
> >
> >
> > - Original Message -
> > From: "Becoming Digital" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Tuesday, 10 June, 2003 06:43
> > Subject: Re: [PHP-DB] Count database-values
> >
> >
> > > So far no problems, but I want to count all these values.
> > > I tried with SUM but with the following code it doesn't work:
> > >
> > > $squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> > posneg = 'af'";
> > >
> > > any suggestions how to do? I want to store it in a
> > variabele ($total)
> > > so I can echo it. (E.g.: $total = 93.63 in this case)
> >
> > If you want the total, you need to do something like the following:
> >
> > $query = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> > posneg = 'af'";
> > $result = mysql_query( $query );
> > $total = mysql_fetch_array( $result );
> > $total = $total['Total'];
> >
> 
> Cheers!
> 
> Mike
> 
> -
> Mike Ford,  Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
> Email: [EMAIL PROTECTED]
> Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Count database-values

2003-06-10 Thread Becoming Digital
Unfortunately, I can't, despite my best efforts, get the data to display unless
it's put inside a loop.  If anyone can tell me how to, I'd just for joy.

Edward Dudlik
Becoming Digital
www.becomingdigital.com


- Original Message -
From: "Ford, Mike [LSS]" <[EMAIL PROTECTED]>
To: "'Becoming Digital'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, 10 June, 2003 11:54
Subject: RE: [PHP-DB] Count database-values


> -Original Message-
> From: Becoming Digital [mailto:[EMAIL PROTECTED]
> Sent: 10 June 2003 12:15
>
> I screwed up my own code.  Silly me.  It should read:

Surely your first attempt is the right one?  There's only ever going to be 1
Total, so why waste a while loop trying to read more than one result row?

> $query = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> posneg = 'af'";
> $result = mysql_query( $query );
> while ( $total = mysql_fetch_array( $result ) )
> {
> $total = $total['Total'];
> }
>
> Edward Dudlik
> Becoming Digital
> www.becomingdigital.com
>
>
> ----- Original Message -
> From: "Becoming Digital" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, 10 June, 2003 06:43
> Subject: Re: [PHP-DB] Count database-values
>
>
> > So far no problems, but I want to count all these values.
> > I tried with SUM but with the following code it doesn't work:
> >
> > $squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> posneg = 'af'";
> >
> > any suggestions how to do? I want to store it in a
> variabele ($total)
> > so I can echo it. (E.g.: $total = 93.63 in this case)
>
> If you want the total, you need to do something like the following:
>
> $query = "SELECT SUM(bedrag) AS Total FROM finance WHERE
> posneg = 'af'";
> $result = mysql_query( $query );
> $total = mysql_fetch_array( $result );
> $total = $total['Total'];
>

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Count database-values

2003-06-10 Thread Ford, Mike [LSS]
> -Original Message-
> From: Becoming Digital [mailto:[EMAIL PROTECTED]
> Sent: 10 June 2003 12:15
> 
> I screwed up my own code.  Silly me.  It should read:

Surely your first attempt is the right one?  There's only ever going to be 1 Total, so 
why waste a while loop trying to read more than one result row?
 
> $query = "SELECT SUM(bedrag) AS Total FROM finance WHERE 
> posneg = 'af'";
> $result = mysql_query( $query );
> while ( $total = mysql_fetch_array( $result ) )
> {
> $total = $total['Total'];
> }
> 
> Edward Dudlik
> Becoming Digital
> www.becomingdigital.com
> 
> 
> - Original Message - 
> From: "Becoming Digital" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, 10 June, 2003 06:43
> Subject: Re: [PHP-DB] Count database-values
> 
> 
> > So far no problems, but I want to count all these values.
> > I tried with SUM but with the following code it doesn't work:
> >
> > $squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE 
> posneg = 'af'";
> >
> > any suggestions how to do? I want to store it in a 
> variabele ($total)
> > so I can echo it. (E.g.: $total = 93.63 in this case)
> 
> If you want the total, you need to do something like the following:
> 
> $query = "SELECT SUM(bedrag) AS Total FROM finance WHERE 
> posneg = 'af'";
> $result = mysql_query( $query );
> $total = mysql_fetch_array( $result );
> $total = $total['Total'];
> 

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Count database-values

2003-06-10 Thread Becoming Digital
I screwed up my own code.  Silly me.  It should read:

$query = "SELECT SUM(bedrag) AS Total FROM finance WHERE posneg = 'af'";
$result = mysql_query( $query );
while ( $total = mysql_fetch_array( $result ) )
{
$total = $total['Total'];
}

Edward Dudlik
Becoming Digital
www.becomingdigital.com


- Original Message - 
From: "Becoming Digital" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, 10 June, 2003 06:43
Subject: Re: [PHP-DB] Count database-values


> So far no problems, but I want to count all these values.
> I tried with SUM but with the following code it doesn't work:
>
> $squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE posneg = 'af'";
>
> any suggestions how to do? I want to store it in a variabele ($total)
> so I can echo it. (E.g.: $total = 93.63 in this case)

If you want the total, you need to do something like the following:

$query = "SELECT SUM(bedrag) AS Total FROM finance WHERE posneg = 'af'";
$result = mysql_query( $query );
$total = mysql_fetch_array( $result );
$total = $total['Total'];

You had forgotten to pull the data out of your result set.  It's a common
mistake. :)

Edward Dudlik
Becoming Digital
www.becomingdigital.com


- Original Message -
From: "Robert Wanadoo" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, 09 June, 2003 11:40
Subject: [PHP-DB] Count database-values


Hi everybody,

I've got a little problem, which I can't solve. It is as follow:
In my database I made a table with different fields.
One of the fields is named 'bedrag' and contains a numeric value like 15.47 or
78.16 and so on.
If I want a value of the table I use in most cases the following code:

";
}
?>

In this case I receive a list like:
15.47
78.16
and so on...

So far no problems, but I want to count all these values. I tried with SUM but
with the following code it doesn't work:

$squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE posneg = 'af'";

any suggestions how to do? I want to store it in a variabele ($total) so I can
echo it. (E.g.: $total = 93.63 in this case)

Thanx in advance,

Robert van der Mast




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Count database-values

2003-06-10 Thread Becoming Digital
> So far no problems, but I want to count all these values.
> I tried with SUM but with the following code it doesn't work:
>
> $squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE posneg = 'af'";
>
> any suggestions how to do? I want to store it in a variabele ($total)
> so I can echo it. (E.g.: $total = 93.63 in this case)

If you want the total, you need to do something like the following:

$query = "SELECT SUM(bedrag) AS Total FROM finance WHERE posneg = 'af'";
$result = mysql_query( $query );
$total = mysql_fetch_array( $result );
$total = $total['Total'];

You had forgotten to pull the data out of your result set.  It's a common
mistake. :)

Edward Dudlik
Becoming Digital
www.becomingdigital.com


- Original Message -
From: "Robert Wanadoo" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, 09 June, 2003 11:40
Subject: [PHP-DB] Count database-values


Hi everybody,

I've got a little problem, which I can't solve. It is as follow:
In my database I made a table with different fields.
One of the fields is named 'bedrag' and contains a numeric value like 15.47 or
78.16 and so on.
If I want a value of the table I use in most cases the following code:

";
}
?>

In this case I receive a list like:
15.47
78.16
and so on...

So far no problems, but I want to count all these values. I tried with SUM but
with the following code it doesn't work:

$squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE posneg = 'af'";

any suggestions how to do? I want to store it in a variabele ($total) so I can
echo it. (E.g.: $total = 93.63 in this case)

Thanx in advance,

Robert van der Mast




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Count database-values

2003-06-09 Thread Robert Wanadoo
Hi everybody,

I've got a little problem, which I can't solve. It is as follow:
In my database I made a table with different fields.
One of the fields is named 'bedrag' and contains a numeric value like 15.47 or 78.16 
and so on.
If I want a value of the table I use in most cases the following code:

";
}
?>

In this case I receive a list like:
15.47
78.16
and so on...

So far no problems, but I want to count all these values. I tried with SUM but with 
the following code it doesn't work:

$squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE posneg = 'af'";

any suggestions how to do? I want to store it in a variabele ($total) so I can echo 
it. (E.g.: $total = 93.63 in this case)

Thanx in advance,

Robert van der Mast



[PHP-DB] Count AND sum columns values

2003-01-20 Thread Cesar Aracena
Hi all,

I have this table which stores products and quantities ordered by
customers, and for billing purposes, I need to fetch not only how many
products but also how many where ordered for each one but not detailed,
but as one big result, so later I can charge for individual gift
packages and stuff... How can I do this in a simple way?

Thanks in advance,

Cesar L. Aracena
[EMAIL PROTECTED]
[EMAIL PROTECTED]
(0299) 156-356688
Neuquén (8300) Capital
Argentina




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] count hours from 2 dates

2002-10-01 Thread José Moreira

  hello, um using this SQL string :


  SELECT computer, date, closedate,UNIX_TIMESTAMP(closedate),
  UNIX_TIMESTAMP(date), (UNIX_TIMESTAMP(closedate) -
  UNIX_TIMESTAMP(date)) / POW(60,2) FROM tracking (18 Records)

computer date closedate UNIX_TIMESTAMP(closedate) UNIX_TIMESTAMP(date) 
(UNIX_TIMESTAMP(closedate) - UNIX_TIMESTAMP(date)) / POW(60,2)
45  2002-06-19 14:12:22  2002-06-19 16:21:10  1024500070  1024492342  
2.1467 
13  2002-01-28 10:04:56  2002-02-19 15:00:30  1014130830  1012212296  
532.9261 
96  2002-06-19 15:46:00  2002-08-21 15:18:21  1029939501  1024497960  
1511.53916667 
45  2002-06-25 15:42:45  2002-06-26 11:11:27  1025086287  1025016165  
19.4783 
239  2002-06-26 15:07:25  2002-06-27 17:21:38  1025194898  1025100445  
26.2369 
188  2002-06-27 10:52:35  2002-06-27 17:55:48  1025196948  1025171555  
7.0536 
173  2002-07-02 15:06:27  2002-07-02 15:29:01  1025620141  1025618787  
0.3761 
43  2002-07-03 17:50:22  2002-08-21 15:17:28  1029939448  1025715022  
1173.4517 
45  2002-07-09 10:54:56  2002-07-09 12:32:07  1026214327  1026208496  
1.6197 
37  2002-07-09 10:57:50  2002-08-01 16:53:30  1028217210  1026208670  
557.9278 
12  2002-07-17 10:24:37  2002-07-18 16:28:19  1027006099  1026897877  
30.0617 
  2002-08-21 15:28:11  2002-08-22 14:46:48  1030024008  1029940091  
23.31027778 
25  2002-08-30 11:01:53  2002-09-04 10:55:27  1031133327  1030701713  
119.8928 
151  2002-09-04 10:01:25  2002-09-04 10:38:42  1031132322  1031130085  
0.62138889 
43  2002-09-06 19:00:47  2002-09-09 15:25:30  1031581530  1031335247  
68.4119 
182  2002-09-19 15:57:44  2002-09-23 10:22:53  1032772973  1032447464  
90.41916667 
193  2002-09-20 10:53:00  2002-09-27 17:48:46  1033145326  1032515580  
174.9294 
6  2002-09-23 10:24:27  2002-09-23 11:10:35  1032775835  1032773067  
0.7689 


im converting seconds to hours with POW ... 1 hour = 60* 60 seconds

i maked and example in RED ... why do i get that mouch hours diference 
in  cases where the dates are days apart 





-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Count and group ?

2002-05-01 Thread Tony James

Hi Dave

Assuming you are using mysql try the following query


select count(Admin_id) as admin1, Admin_id as admin2 from TABLE_NAME group
by admin2


substituting TABLE_NAME  for whatever you have called your table.

Hope this helps

Cheers

Tony James



- Original Message -
From: "Dave Carrera" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 01, 2002 1:02 PM
Subject: [PHP-DB] Count and group ?


Hi All



I have added a row to my table which inputs which admin user has amended
a record in a table on my db.



I have this working but what I would like to do is count how many
instances of the admin id I have stored.



So if my list looks like this..



Admin_id

1

2

2

2

3

3

3

3

3

2

1

1

Then the result I would like to display is this..



Admin (1) = 3 posts

Admin (2) = 4 posts

Admin (3) = 5 posts



Basically displaying the total post each admin has made



Any help or guidance is very appreciated and thank you in advance



Dave Carrera

Php Developer

http://davecarrera.freelancers.net

http://www.davecarrera.com








-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Count and group ?

2002-05-01 Thread Ryan Marrs

assuming these are your fields:

post_id
admin_id

code would look something like:

 admin_id;
print("Admin $i has $Admin[$i] posts.");
}
?>
___
Ryan Marrs
Web Developer

Sandler & Travis Trade Advisory Services, Inc.
248.474.7200 x 183
248.474.8500 (fax)
www.strtrade.com


-Original Message-
From: Dave Carrera [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, May 01, 2002 8:03 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Count and group ?

Hi All

 

I have added a row to my table which inputs which admin user has amended
a record in a table on my db.

 

I have this working but what I would like to do is count how many
instances of the admin id I have stored.

 

So if my list looks like this..

 

Admin_id

1

2

2

2

3

3

3

3

3

2

1

1

Then the result I would like to display is this..

 

Admin (1) = 3 posts

Admin (2) = 4 posts

Admin (3) = 5 posts

 

Basically displaying the total post each admin has made

 

Any help or guidance is very appreciated and thank you in advance

 

Dave Carrera

Php Developer

http://davecarrera.freelancers.net

http://www.davecarrera.com

 

 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Count and group ?

2002-05-01 Thread Dave Carrera

Hi All

 

I have added a row to my table which inputs which admin user has amended
a record in a table on my db.

 

I have this working but what I would like to do is count how many
instances of the admin id I have stored.

 

So if my list looks like this..

 

Admin_id

1

2

2

2

3

3

3

3

3

2

1

1

Then the result I would like to display is this..

 

Admin (1) = 3 posts

Admin (2) = 4 posts

Admin (3) = 5 posts

 

Basically displaying the total post each admin has made

 

Any help or guidance is very appreciated and thank you in advance

 

Dave Carrera

Php Developer

http://davecarrera.freelancers.net

http://www.davecarrera.com

 

 




Re: [PHP-DB] count

2002-04-11 Thread Mike

Sorry, That's not right. This is what I really meant to say.

SELECT COUNT(column) as somename FROM table;
or
Select count(ID) name from $table;

Mike
- Original Message - 
From: "Allen, Ronald L CIV" <[EMAIL PROTECTED]>
To: "Mike" <[EMAIL PROTECTED]>
Sent: Thursday, April 11, 2002 6:52 AM
Subject: RE: [PHP-DB] count


> Something like this
> Select sum(ID) name from $table;
> 
> Where name is some name that I come up with?
> 
> >Ronald L. Allen (MCSE NT, MCP, CCNA)
> SR. LAN/WAN Administrator 
> >SFOR - Hungary, Croatia
> >[EMAIL PROTECTED]
> >[EMAIL PROTECTED]
> >+36-82-50 ext. 22580
> >  DSN: 760-2000
> 
> 
> -Original Message-
> From: Mike [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, April 11, 2002 12:54
> To: Ron Allen
> Cc: php-db list
> Subject: Re: [PHP-DB] count
> 
> 
> SELECT SUM(column) as somename FROM table;
> 
> Mike
> - Original Message -
> From: "Ron Allen" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, April 11, 2002 6:52 AM
> Subject: [PHP-DB] count
> 
> 
> > I would like to count all the total records from a database.  How 
> > would I
> go
> > about doing that???
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.330 / Virus Database: 184 - Release Date: 2/28/02
> 
> 


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.330 / Virus Database: 184 - Release Date: 2/28/02


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] count

2002-04-11 Thread Mike

SELECT SUM(column) as somename FROM table;

Mike
- Original Message -
From: "Ron Allen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 11, 2002 6:52 AM
Subject: [PHP-DB] count


> I would like to count all the total records from a database.  How would I
go
> about doing that???
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.330 / Virus Database: 184 - Release Date: 2/28/02


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] count

2002-04-11 Thread Ron Allen

I would like to count all the total records from a database.  How would I go
about doing that???



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] count from the results

2002-02-09 Thread olinux

USe the count() function in mysql. 
Like this:

 $query = "SELECT count(artist) as howmany FROM artist
WHERE artist LIKE
 'b%' GROUP BY artist ORDER BY artist
 ASC";

 $result = mysql_query($query) or die("Select
 Failed!");
 echo "Total Number Of Artists In
 \"B\":  ";
 echo mysql_num_rows($result);
 echo "";
 if (mysql_num_rows($result)) {
 echo "";
 echo "Artists";
 while ($qry = mysql_fetch_array($result)){
 echo "";
 echo "";
 echo "$qry[artist] ($howmany)";
 }}?>


olinux

> 
> What I would like to know is how do I do a count on
> each result 
> returned.e.g. Benny(4) , Bill(10)
> 


__
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] count from the results

2002-02-09 Thread Jason Wong

On Sunday 10 February 2002 00:55, Barry Rumsey wrote:
> I have the following code:
> $query = "SELECT * FROM artist WHERE artist LIKE 'b%' ORDER BY artist
> ASC";

[snip]

> What I would like to know is how do I do a count on each result
> returned.e.g. Benny(4) , Bill(10)

Try:

$query = "SELECT artist, count(artist) FROM artist WHERE artist LIKE 'b%' 
ORDER BY artist ASC";



-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
Love is being stupid together.
-- Paul Valery
*/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] count from the results

2002-02-09 Thread Barry Rumsey

I have the following code:
$query = "SELECT * FROM artist WHERE artist LIKE 'b%' ORDER BY artist 
ASC";
$result = mysql_query($query) or die("Select Failed!");
echo "Total Number Of Artists In \"B\":  ";
echo mysql_num_rows($result);
echo "";
if (mysql_num_rows($result)) {
echo "";
echo "Artists";
while ($qry = mysql_fetch_array($result)){
echo "";
echo "";
echo $qry[artist];
}}?>

What I would like to know is how do I do a count on each result 
returned.e.g. Benny(4) , Bill(10)



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Count

2002-01-16 Thread Miles Thompson

Afterthought -- you could make this self-maintaining by doing a select for 
$PHP_SELF and inserting the record if mysql_num_rows() returned 0. Downside 
is that it would add greatly to the overhead.

Miles

At 04:42 PM 1/16/2002 -0400, Miles Thompson wrote:
>Barry,
>
>Before leaping to the wrong conclusion, what exactly do you want to count? 
>You can derive the number of times a page has been fetched from your web logs.
>
>Alternately, you could add a  table to your database, and at the top of 
>the page the link points to, after you've established your database 
>connection, etc.:
>$sql_count = "update page_count set views = views + 1 where page = 
>'$PHP_SELF' ";
>mysql_query( $sql_count );
>
>You'll have to add a record for each page to the database, and by now you 
>know how to create tables etc. Justwatch out for reserved words and 
>function names; when I first typed the query I used "count" in place of 
>page_count. "Views" and "page" probably aren't such a hot choices either.
>
>Fetching the counts for the pages involves nothing more than issuing 
>"select * from page_count" and you'll have a per page count of all the 
>clicks to each page.
>
>Miles
>
>At 08:07 AM 1/17/2002 +1300, Barry Rumsey wrote:
>>How do you add a count feature to a link. I can get stuff from the db but 
>>want to know how many times it's been read or click on?
>
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Count

2002-01-16 Thread Miles Thompson

Barry,

Before leaping to the wrong conclusion, what exactly do you want to count? 
You can derive the number of times a page has been fetched from your web logs.

Alternately, you could add a  table to your database, and at the top of the 
page the link points to, after you've established your database connection, 
etc.:
$sql_count = "update page_count set views = views + 1 where page = 
'$PHP_SELF' ";
mysql_query( $sql_count );

You'll have to add a record for each page to the database, and by now you 
know how to create tables etc. Justwatch out for reserved words and 
function names; when I first typed the query I used "count" in place of 
page_count. "Views" and "page" probably aren't such a hot choices either.

Fetching the counts for the pages involves nothing more than issuing 
"select * from page_count" and you'll have a per page count of all the 
clicks to each page.

Miles

At 08:07 AM 1/17/2002 +1300, Barry Rumsey wrote:
>How do you add a count feature to a link. I can get stuff from the db but 
>want to know how many times it's been read or click on?


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Count

2002-01-16 Thread Barry Rumsey

How do you add a count feature to a link. I can get stuff from the db but want to know 
how many times it's been read or click on?



Re: [PHP-DB] count

2002-01-10 Thread Miles Thompson

Barry,

I can't see where you've created $topictest.
Maybe, just before you define $queyr2, you should have the line

$topictest = $row[ "topcitext"];

I also think xp_stories_topicid should be xp_stories.topicid

Try echo 'ing $query2 and see what is printed.

Hope this helps, and that I've not missed something else.

Miles Thompson


At 02:05 AM 1/11/2002 +1300, Barry Rumsey wrote:
>I'm trying to do the following query:
>
>$db_connect = mysql_connect($sqlhostname,$login,$password);
>$base_selection = mysql_select_db($base,$db_connect);
>$query = "SELECT DISTINCT * FROM xp_topics WHERE artist_count='artist' AND 
>topictext LIKE
>   'A%' ORDER BY artist_count ASC limit 0,5"; $req = 
> mysql_query($query);
>   $res = mysql_num_rows($req); if ($res == 0)
>
>
>  { echo "
>   N/A";} else { while($row = mysql_fetch_array($req))
>$query2 = "SELECT SUM(1) FROM xp_stories,xp_topics WHERE xp_topics.topicid 
>= xp_stories_topicid AND xp_topics.topictext = '$topictest'";
>$numtopic = mysql_query($query2) or die("Select Failed!");
>$numtopic = mysql_fetch_array($numtopic);
> { extract($row); echo ("$topictext $numtopic[0]
> "); } }
>?>
>
>Which should return a name and then count how many topics by that person.
>
>If I leave out the query2 statement I do get a list of name, but I can't 
>get query2 to work.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] count

2002-01-10 Thread Barry Rumsey

I'm trying to do the following query:

$db_connect = mysql_connect($sqlhostname,$login,$password);
$base_selection = mysql_select_db($base,$db_connect);
$query = "SELECT DISTINCT * FROM xp_topics WHERE artist_count='artist' AND topictext 
LIKE 
  'A%' ORDER BY artist_count ASC limit 0,5"; $req = mysql_query($query); 
  $res = mysql_num_rows($req); if ($res == 0)


 { echo "
  N/A";} else { while($row = mysql_fetch_array($req))
$query2 = "SELECT SUM(1) FROM xp_stories,xp_topics WHERE xp_topics.topicid = 
xp_stories_topicid AND xp_topics.topictext = '$topictest'";
$numtopic = mysql_query($query2) or die("Select Failed!");
$numtopic = mysql_fetch_array($numtopic);
{ extract($row); echo ("$topictext $numtopic[0]
"); } } 
   ?>

Which should return a name and then count how many topics by that person.

If I leave out the query2 statement I do get a list of name, but I can't get query2 to 
work.



Re: [PHP-DB] count query

2002-01-08 Thread Daniel Barton

Hi,

SELECT SUM(IF(id = '2',1,0)) AS field_name FROM table

Versatile command - you can use it for quite a lot of things.

Barry Rumsey wrote:

> Is it posible to do a count(*) on a tabe where id=2  and count just those that id  = 
>2

--
--
Dan Barton
Terrestrial Program Biologist
Asst. Data Manager
Point Reyes Bird Observatory
http://www.prbo.org
[EMAIL PROTECTED]
[EMAIL PROTECTED]



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] count query

2002-01-08 Thread DL Neil

Barry,

Is it posible to do a count(*) on a tabe where id=2  and count just those that id  = 2


=why don't you try it?
The answer is yes, because count(*) means count the entire number of non-null rows 
selected.
See manual: 3.3.4.8  Counting Rows

=dn



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] count query

2002-01-08 Thread Barry Rumsey

Is it posible to do a count(*) on a tabe where id=2  and count just those that id  = 2



Re: [PHP-DB] count function?

2001-03-30 Thread Phil Jackson

What is retrieved if you do a Select Count(*) from myDb where
condition = parameters?

Seems your result set should contain this value...
Phil J.


DC wrote:

> Hi All
> I cant quite work out how to count the number of rows in my mysql db that
> match a certain critieria and the show that number numericaly in my pages.
>
> Checked books, php.net etc.
>
> Any help is appreciated
>
> Yours Dave C
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] count function?

2001-03-30 Thread DC

Cheers Brian
Thats sounds more like i am looking for
Although i have put the other code examples offered for this prob in my code
folder for later cause you never now when you'll need them.

Cheers

Dave C
""Brian S. Dunworth"" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> At 10:06 AM 3/30/01 -0800, Larry Rivera wrote:
> >I think you have to run multiple queries, ie run some loop after finding
out
> >what topics you wil count from e==>
> >
> >run a select distinct to get the topics
> >run a while or for loop then run queries again like count(*) where
> >topic='$topic'
>
>Better yet (and less db-intensive), run a
>
> SELECT TOPIC,COUNT(*) FROM table_name
>WHERE condition
>GROUP BY TOPIC
>ORDER BY COUNT(*);
>
> That'll return:
>
>   TOPICCOUNT(*)
>    
>   Topic A 8
>   Topic B 3
>   Topic C 1
>   Topic D 0
>   Topic E 0
>
>
>   -
> Brian S. Dunworth
> Sr. Software Development Engineer
> Oracle Database Administrator
> The Printing House, Ltd.
>
> (850) 875-1500  x225
> <[EMAIL PROTECTED]>
>   -
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] count function?

2001-03-30 Thread Brian S. Dunworth

At 10:06 AM 3/30/01 -0800, Larry Rivera wrote:
>I think you have to run multiple queries, ie run some loop after finding out
>what topics you wil count from e==>
>
>run a select distinct to get the topics
>run a while or for loop then run queries again like count(*) where
>topic='$topic'

   Better yet (and less db-intensive), run a

SELECT TOPIC,COUNT(*) FROM table_name
   WHERE condition
   GROUP BY TOPIC
   ORDER BY COUNT(*);

That'll return:

  TOPICCOUNT(*)
   
  Topic A 8
  Topic B 3
  Topic C 1
  Topic D 0
  Topic E 0


  -
Brian S. Dunworth
Sr. Software Development Engineer
Oracle Database Administrator
The Printing House, Ltd.

(850) 875-1500  x225
<[EMAIL PROTECTED]>
  -


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] count function?

2001-03-30 Thread DC

Thanks i will give that ago.

"Andrei Skorokhod" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> if you just need the number
>
> SELECT COUNT(*) FROM table where 
>
> At 06:34 PM 3/30/2001 +0100, DC wrote:
> >Hi All
> >I cant quite work out how to count the number of rows in my mysql db that
> >match a certain critieria and the show that number numericaly in my
pages.
> >
> >Checked books, php.net etc.
> >
> >Any help is appreciated
> >
> >Yours Dave C
> >
> >
> >
> >--
> >PHP Database Mailing List (http://www.php.net/)
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] count function?

2001-03-30 Thread Larry Rivera

try mysql_num_rows function

-Original Message-
From: DC [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 30, 2001 9:34 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] count function?


Hi All
I cant quite work out how to count the number of rows in my mysql db that
match a certain critieria and the show that number numericaly in my pages.

Checked books, php.net etc.

Any help is appreciated

Yours Dave C



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] count function?

2001-03-30 Thread Andrei Skorokhod

if you just need the number

SELECT COUNT(*) FROM table where 

At 06:34 PM 3/30/2001 +0100, DC wrote:
>Hi All
>I cant quite work out how to count the number of rows in my mysql db that
>match a certain critieria and the show that number numericaly in my pages.
>
>Checked books, php.net etc.
>
>Any help is appreciated
>
>Yours Dave C
>
>
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] count function?

2001-03-30 Thread DC

Ok i will get the books out and see if i can construct something.

Thanks for the tip...
 Dave C
""Larry Rivera"" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I think you have to run multiple queries, ie run some loop after finding
out
> what topics you wil count from e==>
>
> run a select distinct to get the topics
> run a while or for loop then run queries again like count(*) where
> topic='$topic'
>
> etc
>
>
> then echo the result to each line
>
>
> -Original Message-
> From: DC [mailto:[EMAIL PROTECTED]]
> Sent: Friday, March 30, 2001 9:53 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] count function?
>
>
> Ok i think i need to expand my help request... my fault
>
> I have a db that uses ids for topics in a message board ie each topic has
> messages of various numbers in them.
>
> >From my select a topic page i hope to put the number of messages in the
> topic, so it visually looks like this sort of...
>
> topic 1 bb (5 posts)
> topic 2 ff (2 posts
>
> and so on.
>
> The only constant i can see in the tables is my posts table which
specifies
> the topic id number.
>
> So i think i am asking how can i count the number of the same topic id
> numbers and show that next to the relevant topic.
>
> Thanks Again
>
> Dave C
> "Andrei Skorokhod" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > if you just need the number
> >
> > SELECT COUNT(*) FROM table where 
> >
> > At 06:34 PM 3/30/2001 +0100, DC wrote:
> > >Hi All
> > >I cant quite work out how to count the number of rows in my mysql db
that
> > >match a certain critieria and the show that number numericaly in my
> pages.
> > >
> > >Checked books, php.net etc.
> > >
> > >Any help is appreciated
> > >
> > >Yours Dave C
> > >
> > >
> > >
> > >--
> > >PHP Database Mailing List (http://www.php.net/)
> > >To unsubscribe, e-mail: [EMAIL PROTECTED]
> > >For additional commands, e-mail: [EMAIL PROTECTED]
> > >To contact the list administrators, e-mail:
[EMAIL PROTECTED]
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] count function?

2001-03-30 Thread Larry Rivera

I think you have to run multiple queries, ie run some loop after finding out
what topics you wil count from e==>

run a select distinct to get the topics
run a while or for loop then run queries again like count(*) where
topic='$topic'

etc


then echo the result to each line


-Original Message-
From: DC [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 30, 2001 9:53 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] count function?


Ok i think i need to expand my help request... my fault

I have a db that uses ids for topics in a message board ie each topic has
messages of various numbers in them.

>From my select a topic page i hope to put the number of messages in the
topic, so it visually looks like this sort of...

topic 1 bb (5 posts)
topic 2 ff (2 posts

and so on.

The only constant i can see in the tables is my posts table which specifies
the topic id number.

So i think i am asking how can i count the number of the same topic id
numbers and show that next to the relevant topic.

Thanks Again

Dave C
"Andrei Skorokhod" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> if you just need the number
>
> SELECT COUNT(*) FROM table where 
>
> At 06:34 PM 3/30/2001 +0100, DC wrote:
> >Hi All
> >I cant quite work out how to count the number of rows in my mysql db that
> >match a certain critieria and the show that number numericaly in my
pages.
> >
> >Checked books, php.net etc.
> >
> >Any help is appreciated
> >
> >Yours Dave C
> >
> >
> >
> >--
> >PHP Database Mailing List (http://www.php.net/)
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] count function?

2001-03-30 Thread DC

Ok i think i need to expand my help request... my fault

I have a db that uses ids for topics in a message board ie each topic has
messages of various numbers in them.

>From my select a topic page i hope to put the number of messages in the
topic, so it visually looks like this sort of...

topic 1 bb (5 posts)
topic 2 ff (2 posts

and so on.

The only constant i can see in the tables is my posts table which specifies
the topic id number.

So i think i am asking how can i count the number of the same topic id
numbers and show that next to the relevant topic.

Thanks Again

Dave C
"Andrei Skorokhod" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> if you just need the number
>
> SELECT COUNT(*) FROM table where 
>
> At 06:34 PM 3/30/2001 +0100, DC wrote:
> >Hi All
> >I cant quite work out how to count the number of rows in my mysql db that
> >match a certain critieria and the show that number numericaly in my
pages.
> >
> >Checked books, php.net etc.
> >
> >Any help is appreciated
> >
> >Yours Dave C
> >
> >
> >
> >--
> >PHP Database Mailing List (http://www.php.net/)
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] count function?

2001-03-30 Thread DC

Hi All
I cant quite work out how to count the number of rows in my mysql db that
match a certain critieria and the show that number numericaly in my pages.

Checked books, php.net etc.

Any help is appreciated

Yours Dave C



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]