Trouble loading custom table database data
I have the following table: wp_customercounts with the following fields: customercountid (unique and auto generated), customerid (post_id) and logged_date.
I want to return the number of counts / clicks that are being stored in the database table. At the moment I have the following script. It should load everything when no customer is selected and only load only the details of a selected customer when selected. Here is the code:
/**
* Load Admin Report
*/
function loadCustomerReport() {
global $wpdb;
$customer_id = $_POST['id']; // customer id
$from_date = $_POST['from']; // from date
$to_date = $_POST['to']; // to date
if ($customer_id == 0){
$sql=" CALL GetCustomerClicks(NULL,'". $from_date ."', '".$to_date."')";
}else{
$sql=" CALL GetCustomerClicks('". $customer_id ."','". $from_date ."', '".$to_date."')";
}
$posts = $wpdb->get_results($sql);
echo("<table class='report'>");
echo("<tr><th>Company</th>");
echo("<th>Hits</th></tr>");
foreach ($posts as $post)
{
echo("<tr>");
echo('<td>'.$post->Company.'</td>');
echo('<td>'.$post->Hits.'</td>');
echo("</tr>");
}
echo("</table>");
die;
}
I have the following table: wp_customercounts with the following fields: customercountid (unique and auto generated), customerid (post_id) and logged_date.
I want to return the number of counts / clicks that are being stored in the database table. At the moment I have the following script. It should load everything when no customer is selected and only load only the details of a selected customer when selected. Here is the code:
/**
* Load Admin Report
*/
function loadCustomerReport() {
global $wpdb;
$customer_id = $_POST['id']; // customer id
$from_date = $_POST['from']; // from date
$to_date = $_POST['to']; // to date
if ($customer_id == 0){
$sql=" CALL GetCustomerClicks(NULL,'". $from_date ."', '".$to_date."')";
}else{
$sql=" CALL GetCustomerClicks('". $customer_id ."','". $from_date ."', '".$to_date."')";
}
$posts = $wpdb->get_results($sql);
echo("<table class='report'>");
echo("<tr><th>Company</th>");
echo("<th>Hits</th></tr>");
foreach ($posts as $post)
{
echo("<tr>");
echo('<td>'.$post->Company.'</td>');
echo('<td>'.$post->Hits.'</td>');
echo("</tr>");
}
echo("</table>");
die;
}
No comments:
Post a Comment