Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP MySQL Query Syntax

Posted on 2014-09-20
4
127 Views
Last Modified: 2014-09-25
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:
$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;
						}                
					}		
				}	
			}					

Open in new window

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.
0
Comment
Question by:rgranlund
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40334572
SELECT meta_value,meta_key
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40334607
OK, That was a DUHHH moment.  Thank you again.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40334609
I have them all the time.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40334841
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.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
php56-php-mcrypt for rhel7 php56 1 54
SQL - format decimal in a string 5 39
selector:validator cookies 4 30
Change static entered data to dynamic with counter 5 12
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question