mysql_num_fields(): supplied argument is not a valid MySQL result resource
I'm working on a custom CMS, made changes to the DB schema and presentation layer. I'm getting an error relative to mysql_num_fields and mysql_num_rows using the following section of code. Can someone give me an idea of why these errors are being raised?
public function viewTableData($db_name,$table_name,$fld01,$w开发者_Python百科here_clause,$order_by,$asc_desc){
           mysql_select_db($db_name);
        if($fld01!="")
        {
            $sql = "Select $fld01 from $table_name";
        }
        else
        {
            $sql = "Select * from $table_name";
        }
        if($where_clause!="")
        {
            $sql=$sql." ".$where_clause;
        }
        if(($order_by!="")&&($asc_desc!=""))
        {
            $sql=$sql." ".$order_by." ".$asc_desc;
        }
        else if(($order_by!="")&&($asc_desc==""))
        {
            $sql=$sql." ".$order_by;
        }
        //return "<br/>sql  :".$sql;
        $result = mysql_query($sql);
        $count_fields = mysql_num_fields($result); 
        $count_rows = mysql_num_rows($result);
        if($count_rows>0)
        {
        $index = 0;
            unset($this->data_array);
          while ($row = mysql_fetch_assoc($result)) {
             $this->data_array[] = $row;
          } // while
    //Finally we release the database resource and return the multi-dimensional array containing all the data.
          mysql_free_result($result);
          return $this->data_array;
       }
    }
Slap an echo mysql_error(); line after the mysql_query line to see the error from the server.
You don't test $result, which can be FALSE upon return from mysql_query()
Also, I would rewrite:
if($order_by!="")
{
    $sql.=" ".$order_by." ".$asc_desc;
}
MySQL doesn't care about extra spaces here and there.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论