mysql_num_rows () ошибка - PullRequest
       3

mysql_num_rows () ошибка

0 голосов
/ 05 января 2011

Я отображаю редактируемую таблицу в drupal со следующим кодом

function _MYMODULE_sql_to_table($sql) { 
  $html = "";    
  // execute sql
  $resource = db_query($sql);    
  // fetch database results in an array
  $results = array();
  while ($row = db_fetch_array($resource)) {

     $results[] = $row;
      $id = $row['id'];
      $email = $row['email'];
      $comment = $row['comment'];
 //     drupal_set_message('Email: '.$email. ' comment: '.$comment. ' id: '.$id);
  }
  // ensure results exist
  if (!count($results)) {
    $html .= "Sorry, no results could be found.";
    return $html;    
  }

  // create an array to contain all table rows
  $rows = array();
  // get a list of column headers
  $columnNames = array_keys($results[0]);

  // loop through results and create table rows
  foreach ($results as $key => $data) {
    // create row data
    $row = array(

    'edit' => l(t('Edit'),"admin/content/test/".$data['id']."/ContactUs", $options=array()),);

    // loop through column names
    foreach ($columnNames as $c) {
      $row[] = array(
        'data' => $data[$c],
        'class' => strtolower(str_replace(' ', '-', $c)),
      );
    }

    // add row to rows array
    $rows[] = $row;

  }

  // loop through column names and create headers
  $header = array();
  foreach ($columnNames as $c) {
    $header[] = array(
      'data' => $c,
      'class' => strtolower(str_replace(' ', '-', $c)),
    );
  }

  // generate table html
  $html .= theme('table', $header, $rows);

  return $html;

}

// then you can call it in your code...
function _MYMODULE_some_page_callback() {

  $html = "";

  $sql = "select * from {contact3}";

  $html .= _MYMODULE_sql_to_table($sql);

  return $html;
}

Тем не менее, я получаю ошибку mysql_num_rows () как

Предупреждение: mysql_num_rows (): предоставленный аргумент не является допустимым ресурсом результата MySQL. Что вызывает это?

1 Ответ

0 голосов
/ 05 января 2011

Какую версию Drupal вы используете?

попробуй db_affected_rows()

или db_num_rows()

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...