回答: 设法在下面回答我自己的问题,仍然欢迎反馈。
问题:我的说法有问题INNER JOIN
。我的代码只用一张表就可以正常工作。
我的目标是根据用户输入表单的邮政编码查询zone_name
from ,然后将其作为表的a 传递到我的查询函数。尽管我正在检查现有的 withing 表和 .zip中的匹配项,但我很难获得结果。woocommerce_shipping_zones
location_code
woocommerce_shipping_zone_locations
woocommerce_shipping_zone_locations
zone_id
woocommerce_shipping_zones
任何帮助是极大的赞赏。
<?php
if(isset($_POST['checkZip']) && isset($_POST['submittedZip'])) {
//is the cast to int needed?
$submittedZip = (int)$_POST['submittedZip'];
debug_to_console($submittedZip);
prntPage($submittedZip);
}
//query for pulling in shipping data
function prntPage($submittedZip) {
global $wpdb;
// The SQL query
if($submittedZip) {
$results = $wpdb-> get_results("SELECT {$wpdb->prefix}woocommerce_shipping_zone_locations.location_code, {$wpdb->prefix}woocommerce_shipping_zones.zone_name ".
"FROM {$wpdb->prefix}woocommerce_shipping_zone_locations ".
"WHERE location_code = '$submittedZip' ".
"INNER JOIN {$wpdb->prefix}woocommerce_shipping_zones ".
"ON {$wpdb->prefix}woocommerce_shipping_zone_locations.zone_id = {$wpdb->prefix}woocommerce_shipping_zones.zone_id ");
// Loop though rows data
foreach( $results as $row ){
print_r($row);
debug_to_console($row);
}
}
}
//function to print to console, used for debugging php
function debug_to_console($data) {
$output = $data;
$typeOfTest = getType($data);
if (is_array($output))
$output = implode(',', $output);
echo "<script>console.log('Debug Objects: " . $output . ", Type: " . $typeOfTest . "' );</script>";
}
?>
四季花海