Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Conot Insert Multiple Records To Db

$
0
0

PLEASE HELP

Insert Only Last Row


In purchase item array such as

Array ( [0] => Array ( [itemid] => 4 [uomid] => 1 [rate] => 30 [quantity] => 122 [typid] => 1 ) [1] => Array ( [itemid] => 5 [uomid] => 3 [rate] => 300 [quantity] => 32 [typid] => 1 ) [2] => Array ( [itemid] => 6 [uomid] => 3 [rate] => 33 [quantity] => 32 [typid] => 1 ) )


Only insert last array

In My Model
public function actionCreate()
	{
		$a=new PurchaseItem;
                 $b=new PurchaseHdr;
    
		if(isset($_POST['PurchaseItem'], $_POST['PurchaseHdr']))
    		{
			
			if(isset($_POST['PurchaseItem']))
    				{
       					 	$valid=true;
							
							echo "<h1>".count($_POST['PurchaseItem']); 
							print_r($_POST['PurchaseItem']);
							echo "</h1>";
							//exit;
        					foreach($_POST['PurchaseItem'] as $key=>$value) 
							{
        				   
						  
            				
							
               				$a->attributes=$value;
							
							$a->save(false);
            				
        					}
        //print_r($a);
						//if($valid)  
//							{// all items are valid
//            // ...do something here
//			
//							print_r($a);
//			
//							}			
    				}
	
	
			

			
	
        
        $b->attributes=$_POST['PurchaseHdr'];
	
       $valid=$b->validate() && $valid;
 
        if($valid)
        {
            // use false parameter to disable validation
          
		   
           $b->save(false);
		   //$a->save(false);
            // ...redirect to another page
        }
		
		 
		
    }
 
    $this->render('create', array(
        'a'=>$a,
        'b'=>$b,
    ));
}
	//}


Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>