wpdb查询返回结果参数的“Array”

时间:2015-03-20 10:15:03

标签: wordpress-plugin wordpress wpdb

我正在处理的这个插件函数解析一个CSV文件,并将其作为HTML表格输出;除此之外,它还查询数据库并获取其中一列的值。

脚本的每个其他部分似乎运行正常,并且除了数据库查询部分之外,我还需要它:

$newdb = new wpdb( 'user', 'password', 'db', 'localhost' );

$results = $newdb->get_results("SELECT ItemID, Price FROM $table WHERE ItemID = $quanid GROUP BY Price ORDER BY COUNT(*) DESC LIMIT 1");


echo('<td>');
echo($results);
echo('</td>');

$ results在HTML输出中显示为“Array”。


function create_table_form() {
$handle = fopen( plugin_dir_path( __FILE__ )  . 'example.csv' , "r" );  
$data = fgetcsv($handle, 1000, ",");
echo('<input type="text" class="search" id="search" placeholder="Search">');
echo('<br>');
echo('<table id="table">    <tr class="hidden">
    <th><b>
        Name</b>
    </th>
    <th><b>
        Fudge</b>
    </th>
    <th><b>
        Price</b>
    </th>
    <th><b>Vote</b>
    </th>
</tr>
<tbody>');
$a = 1;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

    $name = $data[0];
    $quanid = $data[2];
    $table = $data[3];
    unset($data[2]);
    unset($data[3]);
    //generate HTML
    echo('<tr>');
    foreach ($data as $index=>$val) {
        echo('<td>');
        echo htmlentities($val, ENT_QUOTES);
        echo('</td>');


    }
    $newdb = new wpdb( 'user', 'password', 'db', 'localhost' );

    $results = $newdb->get_results("SELECT ItemID, Price FROM $table WHERE ItemID = $quanid GROUP BY Price ORDER BY COUNT(*) DESC LIMIT 1");


    echo('<td>');
    echo($results);
    echo('</td>');

    echo('<td>
        <button class="toggler" data-prod-cat="' . $cssId . '">Vote</button>
    </td>');
    echo('</tr>');
    echo('<tr class="cat' . $cssId . ' hidden" style="display:none">');
    echo('<td colspan="4" style="white-space: nowrap">Enter ' . $name . ' Price:
    <input type="text" maxlength="4" name="' . $quanid . '" value="" class="input" />&nbsp;
    <button class="submit" type="submit" value="Submit">Submit</button>
    </td>
    </tr>');

    $cssId = 'row-'.$a;

$a++;
}

echo("</table>");
fclose($handle);

}

1 个答案:

答案 0 :(得分:1)

将echo($ results)更改为:

print_r( $results );
相关问题