0

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?

1
  • Are you sure this is because the rows are null? Couldn't it be that an error happens before that, e.g. in the db_fetch_array()? Can you make a test output after the while loop to exclude that possibility? Commented May 11, 2010 at 14:29

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.