Solved

Need a bit of help understanding some PHP

Posted on 2009-04-01
6
215 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 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This video teaches users how to migrate an existing Wordpress website to a new domain.

623 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