Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need a bit of help understanding some PHP

Posted on 2009-04-01
6
Medium Priority
?
218 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
[X]
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
  • 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 1500 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
Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

715 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