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

Earl Miles merlin at logrus.com
Wed Jan 18 17:22:38 UTC 2006


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.


More information about the support mailing list