Page 1 of 1

While Statement Inside If

Posted: Mon Nov 17, 2008 3:44 am
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.

Re: While Statement Inside If

Posted: Mon Nov 17, 2008 3:56 am
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.

Re: While Statement Inside If

Posted: Mon Nov 17, 2008 4:01 am
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";
            }
 

Re: While Statement Inside If

Posted: Mon Nov 17, 2008 5:23 am
by cosmicsafari
I got it too work :D