开发者

Drupal - db_fetch_array returns NULL for every row

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)";
开发者_JS百科    $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?


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


$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...


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜