While Statement Inside If

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cosmicsafari
Forum Newbie
Posts: 3
Joined: Mon Nov 17, 2008 3:38 am

While Statement Inside If

Post by cosmicsafari »

Hey all,
Im having a few problems with editing the following code:

Code: Select all

    if(isset($_REQUEST['Include'])) 
        {
            $z=1;
            $addtocart=$_REQUEST['SpecialOutfit-0'];
            $chapcart->addToCart($addtocart,1);
                        
        }
 
This code adds a special offer to the shopping cart of the website, what i want however is for multiple special offers to be added to the website when there are multiple choices for the user, so i changed it to this.

Code: Select all

 
    if(isset($_REQUEST['Include'])) 
        {
            $z=1;
            $joe=0;
            //$addtocart=$_REQUEST['SpecialOutfit-0'];
            $joe=$_REQUEST['joe'];
            $i=0;
            while($i != $joe)
            {
            $addtocart=$_REQUEST['SpecialOutfit-'.$i.''];
            $chapcart->addToCart($addtocart,1); 
            }
            //$chapcart->addToCart($addtocart,1);       
 
        }
 
I should mention that the variable $joe stores the amount of drop downs that the user is presented with, thus in other words i want it special offer info to be iterated $joe times. I hope this explains enough for someone to help me.

Thanks in advance.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: While Statement Inside If

Post by requinix »

Please tell me your name isn't Joe...

So what's the problem? And when you answer that, post the code for the form.
cosmicsafari
Forum Newbie
Posts: 3
Joined: Mon Nov 17, 2008 3:38 am

Re: While Statement Inside If

Post by cosmicsafari »

lol unfortunatley it is and i just used my name as i was trying to establish something that worked before trying to think up another unique variable name lol

Anyway the code for the form is created dyanmically and will take ages to explain but $joe comes from a hidden field value which stores the number of drop downs the user is shown. This part of the code works, i echoed $joe and it does indeed display the correct int value, the problem it seems is that somewhere in the code it crashes and thus nothing is displayed in the browser.

This is the code which deals with the special aspect of the form, although im not sure if this will be relavent.

Code: Select all

 
            if($row[0]==$pieces[0])
            {
                $specchoice=mysql_query("SELECT aref,name from attribute where ProductID='".$pieces[1]."'") or die(mysql_error());
                $specialcount3=mysql_num_rows($specchoice);
                $choice="Add To Cart : <input type=\"checkbox\" name=\"Include\" value=\"Add\"><br/><input type=\"hidden\" name=\"joe\" value=\"$specrow[5]\">";
                
                
                $i=0;
                while($i != $specrow[5]){
                $specchoice=mysql_query("SELECT aref,name from attribute where ProductID='".$pieces[1]."'") or die(mysql_error());
 
                $specialcount3=mysql_num_rows($specchoice);
                $choice.="<select name=\"SpecialOutfit-".$i."\">";      
                while($test2=mysql_fetch_row($specchoice))
                {
                    $choice.="<option value=\"".$test2[0]."\">".$test2[1]."</option>\n";
                }
                mysql_free_result($specchoice);
                $i++;
                $choice.="</select><br>\n";
            }
 
cosmicsafari
Forum Newbie
Posts: 3
Joined: Mon Nov 17, 2008 3:38 am

Re: While Statement Inside If

Post by cosmicsafari »

I got it too work :D
Post Reply