views:

164

answers:

3

I'm using Drupal's db_fetch_array to fetch rows from my db_query. However, every row returned is equal to NULL. Typing the query into PHP myadmin works, so I have no idea whats going on. db_num_rows returns the number of rows as well. Here is the code:

if(count($rebuild_ids))
  {
    $ids=implode(",",$rebuild_ids);
    $type_stmt = "SELECT * from {" . ItemType::$type_table_name . "} where id IN ($ids)";
    $new_items=db_query($type_stmt);
    if(!$new_items || db_num_rows($new_items) == 0)
    {
        return;
    }
    while($row = db_fetch_array($new_items));
    {
      if ($row!=NULL)
      {
          echo "I work!"
          $game_items[] = $row['id'];
          ItemInstance::$nid_to_item_type_code[$row['nid']] = $row['id'];
      }
    }
  }

However, it never gets into the third if statement (i.e. never echos "I work!") Any ideas?

A: 

$row is not NULL by definition, otherwise it wouldn´t even reach the third if statement.

There is no need to check if $row contains information, the while loop already takes care of that, but if you want to check anyway, use something like empty($row) or count($row) > 0; don´t compare an array with NULL.

The checking is completely unnecessary though...

jeroen
A: 

K figured it out. It was the semicolon after the while loop!

darudude
+1  A: 

Friendly advice: Drupal has a coding standards http://drupal.org/coding-standards -- it helps to keep them. This error would have been a lot more obvious that way....

Also putting variables in a query is a huge no-no see http://drupal.org/writing-secure-code

chx