[support] db_num_rows(db_query(...)) issue

Kobus Myburgh itbjdm at puknet.puk.ac.za
Thu Jan 19 06:00:55 UTC 2006


Thanks a lot, Merlin! :-)

Yup, as I thought... I did something stupid. It makes PERFECT sense now.

Okay - my percentage counter is now working  at www.drupal.co.za :-)

Thanks again!

Kobus


>>> merlin at logrus.com 1/18/2006 7:22:38 PM >>>
Kobus Myburgh wrote:
> Hi,
> 
> I am making a custom block for my Afrikaans translation Drupal site (www.drupal.co.za) with the following SQL query:
> 
> <?php
>   $result1 = db_num_rows(db_query("SELECT COUNT(`translation`) from {locales_target} WHERE `translation` != ''"));
>   $result2 = db_num_rows(db_query("SELECT COUNT(`translation`) from {locales_target}"));
>   print $result1 . " van " . $result2 . " stringe (" . $result1 / $result2 * 100 . "%)";
> ?>
> 
> The result is this:
> 
> 1 van 1 stringe (100%)
> 
> This is incorrect, even though, if I add these queries directly to phpMyAdmin, I get the values 942 and 1292 respectively. Of course, I have to replace {locales_target} with `locales_target` in phpMyAdmin, but nevertheless, either I am doing really silly wrong or something is terribly wrong with my copy of Drupal.
> 
> Could someone please indicate where my problem lies? Perhaps fix these queries if they are broken?
> 
> Thanks in advance,
> 
> Kobus
> 
> 

The COUNT query returns 1 row with 1 column. That column is the count.

You want to use db_result, not db_num_rows.
-- 
[ Drupal support list | http://lists.drupal.org/ ]



More information about the support mailing list