mysql\u num\u rows()错误
我用以下代码在drupal中显示一个可编辑的表mysql\u num\u rows()错误,mysql,drupal,Mysql,Drupal,我用以下代码在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)) { $re
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结果资源。是什么原因造成的
您使用的是哪个版本的Drupal 尝试
db\u受影响的行()
或者
db_num_rows()
当这种情况发生时,意味着查询失败,请检查与查询相关的mysql_num_rows
我知道,确切的错误是警告:mysql_num_rows():在第176行的C:\wamp\www\drupal-6.19\includes\database.mysql.inc中提供的参数不是有效的mysql结果资源。当我重新加载页面时,错误消失了,但当我提交表单时,错误就出现了。我需要改变什么?我假设我需要将db_受影响的_行放在运行“select”查询时可以正常工作的位置。mysql_num_row()错误仅在运行“更新”查询时出现。如何为“更新”查询修改它?