Robert Granlund
asked on
PHP MySQL Query Syntax
I asked a very similar question earlier and I thought I had it working. However, I have come up with a new error and I'm not sure how to fix it:
Undefined variable: meta_key in ... and the line above is line 24.
$check_alt = "SELECT meta_value
FROM wp_woocommerce_order_itemmeta
WHERE (meta_key = 'Bicycle Info - Primary Operator First Name'
OR meta_key = 'Bicycle Info - Primary Operator Last Name'
OR meta_key = 'Bicycle Info - Bicycle Serial Number'
OR meta_key = '_line_total'
OR meta_key = 'Select My Deductible'
OR meta_key = 'Type of Bicycle'
OR meta_key = 'Bicycle Info - Liability Amount'
OR meta_key = '_subscription_status')
AND order_item_id = :order_id ";
$checking_alt = $pdo->prepare($check_alt);
$checking_alt->execute(array(':order_id' => $order_id)) or die(print_r($checking_alt -> errorInfo()));
$res_alt = $checking_alt->fetchAll();
if ($res_alt) {
echo "<pre>";
var_dump( $res_alt );
foreach ($res_alt as $rows) {
if($rows->meta_key == "_line_total") {
$total = $rows->meta_value;
}
elseif($rows->meta_key == "Bicycle Info - Bicycle Serial Number") {
$sn = $rows->meta_value;
}
elseif($rows->meta_key == "Bicycle Info - Primary Operator First Name") {
$fn = $rows->meta_value;
}
elseif($rows->meta_key == "Bicycle Info - Primary Operator Last Name") {
$ln = $rows->meta_value;
}
elseif($rows->meta_key == "Bicycle Info - Deductible Amount") {
$deduc = $rows->meta_value;
}
elseif($rows->meta_key == "Bicycle Info - Type of Bicycle") {
$bike_type = $rows->meta_value;
}
elseif($rows->meta_key == "Bicycle Info - Liability Amount") {
$liabil = $rows->meta_value;
}
elseif($rows->meta_key == '_subscription_status') {
$status = $rows->meta_value;
}
}
}
}
The Var_Dump gives me all of the proper strings But I get the error:Undefined variable: meta_key in ... and the line above is line 24.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have them all the time.
No points for this, please. Anything not in the SELECT list is not in the results set. You do not have to put columns into the SELECT list if you only want to use them in other clauses (WHERE or ORDER BY, for example), but if you want the query to return columns in the results set, they have to be listed in SELECT.
ASKER