www.webdeveloper.com
Results 1 to 1 of 1

Thread: array problem

  1. #1
    Join Date
    Feb 2006
    Location
    india
    Posts
    680

    array problem

    Hi all,

    I am facing a problem of arrays.The fact is that I am getting the array values but when i am running 2 arrays under a single for loop then I am only getting null values for the quantities....lets give you the code so that you can understand where the problem lies.

    output of
    echo "Key1: $key1; Value1: $value1<br />\n";
    echo "Key2: $key2; Value2: $value2<br />\n";

    is

    Key1: 0; Value1: 1475
    Key2: 0; Value2:
    insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values('1','1475','','180.05','0')
    Key1: 1; Value1: 1476
    Key2: 1; Value2:
    insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values('1','1476','','196.74','0')
    Key1: ; Value1:
    Key2: 2; Value2: 3
    Key1: ; Value1:
    Key2: 3; Value2: 5

    As you see I am not getting the net_total and quantity

    PHP Code:
    //if the form is submitted
    if(isset($_POST['image1_x']))
    {
    $pid=$_POST['pid'];//product id
    $quantity=$_POST['quantity'];
    $item_price=$_POST['item_price'];
    if(
    $pid!="")
    {
            for(
                 ;
                 list(
    $key1$value1 ) = each$pid ) ,
                 list(
    $key2$value2 ) = each$quantity )                  
                 ;
            ) {        
        echo 
    "Key1: $key1; Value1: $value1<br />\n";
        echo 
    "Key2: $key2; Value2: $value2<br />\n";            
                foreach(
    $item_price as $k=>$v)
                {                    
                list(
    $v1,$v2)=explode("#",$v);//(price and pid)
                   
                                           
    if($value1!="")
                {                            
                if(
    $v2==$value1)//if pid==pid
                
    {
                
    $net_total=$value2*$v1;                                            
                
    $s_pro="select pid from temp_cart where pid='$value1' and cart_id='$cart_id'";// TO SEE IF THE SELECTED PRODUCT IS ALREADY IN THE CART OR NOT
                
                
    $q_pro=mysql_query($s_pro) or die(mysql_error());
                
    $numrows=mysql_num_rows($q_pro);                    if($numrows=="")
                {            
                
    //echo "insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values('$cart_id','$value1','$value2','$v1','$net_total')";
                
    $s_temp="insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values('$cart_id','$value1','$value2','$v1','$net_total')";
                
    $q_temp=mysql_query($s_temp) or die(mysql_error());
                
    header("location:cart.php");            
                }
                else
                {
                
    $err=1;//one of the selected product is already in the cart
                
    }
                }
                }                                         
                }                                            
              }        
    }          
    else
    {
    $emp=1;//no product has been selected
    }            

    HTML Code:
    //html form
    <form name="form1" method="post" action="">
                  <table width="95%" align="center" cellpadding="3" class="table">
    <tr> 
                      <td width="25%" class="text" align="center"> 
                        <?=$icode;?>                  
                      </td>
                      <td width="12%" class="text" align="center"> 
                        <?=$design;?>
                      </td>                  
                      <td width="9%" class="text" align="center"> 
                        <input type="text" name="quantity[]" value="" size="7">
                      </td>
                      <td width="9%" class="text" align="center"> 
                        <input type="checkbox" name="pid[]" value="<?=$pid;?>">
                      </td>
                      <td width="10%" class="text" align="center"> 
                        <?=$list;?>                  
                      </td>
                                       	 <input type="hidden" name="item_price[]" value="<?=$list."#".$pid;?>">
    	                </tr>
                                 <tr> 
                      <td colspan="9" class="Subtitle" align="center"> 
                        <input type="image" img src="images/addtocart.gif" width="85" height="17" name="image1" value="up">
                      </td>
                    </tr>
                  </table>			  			   
                </form>
    Please suggest how to get the values from the quantity array

    Thanks in advance for your co-operation.
    Raj
    Last edited by raj_2006; 10-03-2006 at 09:22 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles