Solved

Need a bit of help understanding some PHP

Posted on 2009-04-01
6
212 Views
Last Modified: 2012-05-06
Take a look at the code below this....

I want to trigger another variation in this code.  I've already written the variation as this:

<?php
  $promo_title="Promotions";
  $promos[1]["sc_amount"]=40;

  $promos[2]["sc_amount"]=100; //            <-- variation
?>
 
I also have a different SQL string to look for, which is handy....

"and promotion_offer_1 like '%Offer%';

What I want to do is simply incorporate this.
So essentially, the same thing but with Offer for the SQL and the 'promos' code as 2

require("promo.php");
		global $sc_total;
		$sql_string.=" and promotion_offer_1 like '%True%' ";
				
		
		if ($sc_total<$promos[1]["sc_amount"]) 					
				
		{
			$sql_string.=" and 1=0 ";
			
			require("info_promotions.php");
		}	
		
	}

Open in new window

0
Comment
Question by:chriscounter07
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:twocandles
ID: 24039936
But what's your actual target? Apply a new filter to the query? Could you describe your problem a little more?

I'm understanding this:

You have a promo_1 applied to a value equal or greater than $promos[1]["sc_amount"] and you want to add a second promo with $promos[2]["sc_amount"] "trigger" value to be added to your query. Is that right?
0
 

Author Comment

by:chriscounter07
ID: 24039973
You have a promo_1 applied to a value equal or greater than $promos[1]["sc_amount"] and you want to add a second promo with $promos[2]["sc_amount"] "trigger" value to be added to your query. Is that right?


This is statement is correct.  I just want it to do two things rather than one at two different values
0
 
LVL 6

Accepted Solution

by:
twocandles earned 500 total points
ID: 24040068
OK, I modified your piece of code. I don't know if it works, but I gess you'll get the idea.

The where clause has to be modified in order to take into account the new filter with an OR.

require("promo.php");
                global $sc_total;
                $sql_string.=" and ( promotion_offer_1 like '%True%' ";
                                
                
                if ($sc_total<$promos[1]["sc_amount"])                                  
                                
                {
                        $sql_string.=" and 1=0 ";
                        
                        require("info_promotions.php");
                }       
                $sql_string .= ") or ( promotion_offer_1 like '%Offer% ";
                if ($sc_total<$promos[2]["sc_amount"])                                  
                                
                {
                        $sql_string.=" and 1=0 ";
                        
                        require("info_promotions.php");
                }       
                $sql_string .= ")"; 
                
        }

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 6

Expert Comment

by:twocandles
ID: 24040094
There's a opening parenthesis missing after the first AND and a closing parenthesis in the last line (so the operator precedence between the outer AND and the inner OR don't become a problem)
0
 

Author Comment

by:chriscounter07
ID: 24040188
right.  Shall give that a go then....
0
 

Author Closing Comment

by:chriscounter07
ID: 31565318
I could only put Good as a grade because the code in fact crashed the SQL server.  However, a guideline was what I requested and this is what I got.  I am very happy with the code and I can see by reading it it only requires a subtle change to make it work for me.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video teaches users how to migrate an existing Wordpress website to a new domain.

785 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