How to open and close a loop using the PHP Eval () function?

What I'm trying to do is create from which all the attributes of these products will be requested. I have 4 different types of product. One type of product is a group product, and when the product is a group product, we need to navigate through all the subproducts of the group product and request the attribute of all subfiles. I don’t want to duplicate code based on the type of product, so try using the PHP Eval () function to start and close the loop when required. But some, how it does not work, can someone please hepl me?

Here is my code

//To Get Product Information we will call getProductInfo function      
$arrProdInfo = getProductInfo($prodId);      
$pName = $arrProdInfo['name'];      
$pCode = $arrProdInfo['code'];      
$pType = $arrProdInfo['producttype'];          
//Define two Empty variable in which we will store the string to evaluate through PHP Eval() function      
$topStr1 = "";      
$botStr1 = "";  

//If the product type is G(Group Product) then we need to loop through all the products within this group      
if ($pType == "G") {        
 //To fetch all the products within a group product we will call getGroupProd function      
    $rsltGroupProd = getGroupProd($prodId);              
    //Set the first string to star the loop      
    $topStr1 = "while($rowGroupProd = $rsltGroupProd->fetchAssoc()){      
                    $prodId = $rowGroupProd['relproductid'];       
                    if(!is_numeric($prodId)) $prodId = 0;      
                    $pName = $rowGroupProd['name'];      
                    $pCode = $rowGroupProd['code'];      
                    $pType = $rowGroupProd['producttype'];  
                ";      
    //Set second string to close the loop       
$botStr1 = "}";      
}      

//Eval() should start the loop if it a Group Product else will not do noting      
eval($topStr1);  

//A big form to fetch all the attributes of product will be generated here      

//Eval() should end the loop if it a Group Product else will not do noting      
eval($botStr1);
+3
source share
2 answers

. eval().

+1

.

. , , , . a, ...

R & D Eval(), ...

, Ekta..

0

All Articles