Solved

Need a bit of help understanding some PHP

Posted on 2009-04-01
6
213 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

820 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