我更新了代码,但在数据之前获得了一些标签
<br />
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span>
警告:调用的 wpdb::p repare(( 缺少参数 2 C:''wamp''www''wordpress''wp-content''plugins''sinetiks-schools''deped_rpci.php 在第 14 行并在 C:''wamp''www''wordpress''wp-include''wp-db 中定义.php 在1246线上
</th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0000</td><td bgcolor='#eeeeec' align='right'>312032</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:'wamp'www'wordpress'wp-admin'admin.php' bgcolor='#eeeeec'>..'admin.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>331856</td><td bgcolor='#eeeeec'>require_once( <font color='#00bb00'>'C:'wamp'www'wordpress'wp-load.php'</font> )</td><td title='C:'wamp'www'wordpress'wp-admin'admin.php' bgcolor='#eeeeec'>..'admin.php<b>:</b>31</td></tr>
这是代码
<?php if (isset($_POST['exp'])) {
$wpdb->show_errors();
global $wpdb;
// Grab any post values you sent with your submit function
$DownloadReportFrom = "ReportDateFrom";
$DownloadReportTo = "ReportDateFrom";
// Build your query
$MyQuery = $wpdb->get_results($wpdb->prepare('SELECT * FROM wp_rpci_rpci'));
// Process report request
if (! $MyQuery) {
$Error = $wpdb->print_error();
die("The following error was found: $Error");
} else {
// Prepare our csv download
// Set header row values
$csv_fields=array();
$csv_fields[] = 'Field Name 1';
$csv_fields[] = 'Field Name 2';
$csv_fields[] = 'Field Name 1';
$csv_fields[] = 'Field Name 2';
$csv_fields[] = 'Field Name 1';
$csv_fields[] = 'Field Name 2';
$output_filename = 'MyReport_' . $DownloadReportFrom .'-'. $DownloadReportTo . '.csv';
$output_handle = @fopen( 'php://output', 'w' );
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Content-Description: File Transfer' );
header( 'Content-type: text/csv' );
header( 'Content-Disposition: attachment; filename=' . $output_filename );
header( 'Expires: 0' );
header( 'Pragma: public' );
// Insert header row
fputcsv( $output_handle, $csv_fields );
// Parse results to csv format
foreach ($MyQuery as $Result) {
$leadArray = (array) $Result; // Cast the Object to an array
// Add row to file
fputcsv( $output_handle, $leadArray );
}
// Close output file stream
fclose( $output_handle );
die();
exit();
}
}
?>
我得到一些表,然后它在表标签后显示数据库行
你不使用mysqli_query而是使用 wpdb::query。
由于 wpdb::query 返回受影响/选择的行数,您将整数传递到mysqli_fetch_assoc并且由于明显的原因而失败,因为它期望mysqli_result而不是某个数字。
你需要获得真正的mysqli连接,然后你的代码才能工作。
我让它工作:)
我只是消除了多余的论点
这是代码
$wpdb->show_errors();
global $wpdb;
// Grab any post values you sent with your submit function
$DownloadReportFrom = "ReportDateFrom";
$DownloadReportTo = "ReportDateFrom";
// Build your query
// $MyQuery = $wpdb->get_results($wpdb->prepare('SELECT * FROM wp_rpci_rpci')); -Delete the ($wpdb->prepare
$MyQuery = $wpdb->get_results('SELECT * FROM wp_rpci_rpci');
// Process report request
if (! $MyQuery) {
$Error = $wpdb->print_error();
die("The following error was found: $Error");
} else {
// Prepare our csv download
// Set header row values
$csv_fields=array();
$csv_fields[] = 'Field Name 1';
$csv_fields[] = 'Field Name 2';
$output_filename = 'MyReport_' . $DownloadReportFrom .'-'. $DownloadReportTo . '.csv';
$output_handle = @fopen( 'php://output', 'w' );
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Content-Description: File Transfer' );
header( 'Content-type: text/csv' );
header( 'Content-Disposition: attachment; filename=' . $output_filename );
header( 'Expires: 0' );
header( 'Pragma: public' );
// Insert header row
fputcsv( $output_handle, $csv_fields );
// Parse results to csv format
foreach ($MyQuery as $Result) {
$leadArray = (array) $Result; // Cast the Object to an array
// Add row to file
fputcsv( $output_handle, $leadArray );
}
// Close output file stream
fclose( $output_handle );
die();
}