警告mysql_query()期望参数2是追索,给定对象

时间:2015-07-02 13:26:16

标签: php mysql wordpress

在wordpress网站中,此代码会出现以下错误 我试图将其更改为mysqli,但同样的错误 任何人都知道问题在哪里,如何处理。 我在这里搜索了很多答案,但没有为我工作。

此代码是文件“class_design.php”的一部分

function MYORDERS($user_id){

global $wpdb,$PPT, $ThemeDesign, $userdata;
get_currentuserinfo(); 
$content=""; 
$dwl_content=""; 
$td=1; 
$STRING ='<input type="hidden" value="" id="moreinfodiv" name="moreinfodiv">';
$date_format = get_option('date_format') . ' ' . get_option('time_format');
if(!is_numeric($user_id)){ die("nice try!"); }


$SQL = "SELECT * FROM 
       ".$wpdb->prefix."orderdata
       WHERE cus_id='".$userdata->ID."'
       GROUP BY order_id
       ORDER BY autoid DESC";  

$posts = mysql_query($SQL, $wpdb->dbh) or die(mysql_error().' on line: '.__LINE__);

  if ($posts && mysql_num_rows($posts) > 0) {

    while ($thepost = mysql_fetch_object($posts)) { if($thepost->order_total > 0){

    if($thepost->order_status ==0){  
    $status = $PPT->_e(array('myaccount','_paymentstatus0'));
    }elseif($thepost->order_status ==3){ 
    $status = "<b style='color:green;'>".$PPT->_e(array('myaccount','_paymentstatus1'))."</b>";
    }elseif($thepost->order_status ==5){ 
    $status = "<b style='color:green;'>".$PPT->_e(array('myaccount','_paymentstatus2'))."</b>";
    }elseif($thepost->order_status ==6){  
    $status = "<b style='color:red;'>".$PPT->_e(array('myaccount','_paymentstatus3'))."</b>";
    }elseif($thepost->order_status ==7){ 
    $status = "<b style='color:blue;'>".$PPT->_e(array('myaccount','_paymentstatus4'))."</b>";
    }elseif($thepost->order_status ==8){ 
    $status = "<b>".$PPT->_e(array('myaccount','_paymentstatus5'))."</b>";
    }  

error appears in the page

1 个答案:

答案 0 :(得分:2)

您正在将$wpdb对象传递给mysql_query,该对象需要一个资源,即一个mysql连接。

尝试直接使用$wpdb对象:

$SQL = "SELECT * FROM 
       ".$wpdb->prefix."orderdata
       WHERE cus_id='".$userdata->ID."' 
       GROUP BY order_id 
       ORDER BY autoid DESC";
$results = $wpdb->get_results($SQL);

foreach ($posts as $post) {

    // do your business here

}