Solved

Need a bit of help understanding some PHP

Posted on 2009-04-01
6
208 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 6

Expert Comment

by:twocandles
Comment Utility
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
Comment Utility
right.  Shall give that a go then....
0
 

Author Closing Comment

by:chriscounter07
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now