ivalea Posted October 5, 2006 Share Posted October 5, 2006 Hi -I'm building a site with a shopping cart and on the checkout success page I would like to check and see what model number they purchased and then run a query based on which model number it was. What I'm trying to find out is how would I assign my variable for this? Right now I have this:[code]if ($partno = 'B-100'){ //then run query}[/code]Basically all part no's will begin with B-. I tried the || w/o any success:[code]if ($partno = 'B-100' || 'B-200') {//then run query}[/code]Any easy ways to accomplish this? Thanks in advance! :) Quote Link to comment Share on other sites More sharing options...
Tandem Posted October 5, 2006 Share Posted October 5, 2006 You need to use double ='s.e.g[code]if ($partno == "B-100"){ //query here}[/code] Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted October 5, 2006 Share Posted October 5, 2006 That if statement is all kinds of wrong for what you want.Let's start with the syntax of if:if([b]expr[/b]){[i]stmts[/i]}If [b]expr[/b] is true, then do [i]stmts[/i].Now, what you want to do is check if $partno is equal to any of multiple possibilities. Let's say it in english, if $partno is equal to XXX OR $partno is equal to YYY OR $partno is equal to ZZZ, then do something.if($partno == 'XXX' || $partno == 'YYY' || $partno == 'ZZZ'){[i]something[/i]}There are a couple difference between that and what you wrote. The first is the usage of [b]==[/b] instead of =. Also, you have to check $partno against each possible value separately.Here is what happens with the original [b]$partno = 'B-100' || 'B-200'[/b]. Remember, if is trying to evaluate an expression as true or false. We will also need to look at PHP's operator precedence, http://aspn.activestate.com/ASPN/docs/PHP/language.operators.precedence.htmlFrom the manual, we can see that [b]||[/b] has a higher precedence than [b]=[/b]. So here's what happens:[list] [*]'B-100' || 'B-200' evaluates first. A string is non-null so evalutes to true. true OR true gives true. [*]$partno = true evaluates next. $partno is [b]reassigned[/b] to the value true. [*]$partno is evaluated next. $partno now has the value true, and the expression passes the true / false test.[/list]I just wanted to clear up the way in which PHP evaluates expressions for you because without knowing that you'll run into a lot of trouble later.Let's think about the process of a shopping cart from the user's perspective:1) User clicks a shopping link2) User might filter their shopping categories, repeatable step3) User adds items to their cart, repeatable step4) User submits order5) User prints or saves order confirmationNow let's think about the process from your side of things:1) Each time the user filters the products or views a shopping cart page, you're going to have to run some sort of database query to get the proper products.2) For each product, that query is going to return information such as if it's in stock, the unit price, the product name, the model number, the product description, etc.3) You will then have to format all of these products into an HTML form so the user can actually shop.4) When the user submits the order, all of their selections will be available in $_POST5) You look at the $_POST data and create new orders in your site's database as necessary.Basically, what I'm trying to understand is why do you need to branch on the confirmation page based off of what was selected? Most, if not all, of the necessary information should already be contained within $_POST when the buyer submits the order. Quote Link to comment Share on other sites More sharing options...
ivalea Posted October 5, 2006 Author Share Posted October 5, 2006 Thanks roopert! Basically what I'm doing is building a menu based upon which product a member has purchased. There should be up to ten model #'s that once purchased give the user access to the corresponding directory. So on this success page, it should automatically enter the user in a separate members table - since there are other products other than these 10 - later, on their main account page, I use a switch to build the menu based upon the information included in the members table.Unfortunately, I tried the script you provided and it didn't work. I totally get what you were trying to explain so I'll try something else. Thanks again! :) Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted October 6, 2006 Share Posted October 6, 2006 So what you're saying is that by purchasing a product they gain access to a menu? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.