Saturday, 24 August 2013

Optimize PHP Code

Optimize PHP Code

Any suggestions, below is function of toy variant - function
loadProductVarients
At present its displaying :-
a) Toy Variant Name Only, wherein i intend to achieve product name and
variant name. For example if Hotwheels is company, Ferrari is Product and
Zsi is its Variant.
Now below function is displaying only Zsi as variant name, i intend to
achieve Ferrari Zsi as variant name
I think the variable of product needs to be added in $temp1, but despite
using many combinations - i am unable to achieve it.
b) Second is getting PHP Notice: Undefined variable: temp1 & temp2 Notice
in function loadproductvarients
I am on learning PHP - your help and advise will be much appreciated !!
function loadProductVarients($id){
$mainframe =& JFactory::getApplication();
$option = JRequest::getCmd('option');
$database =& JFactory::getDBO();
global $Itemid;
$Vcond="";
$sql = "Select * from #__newcar_variants Where
v_prod_id='".$id."' $Vcond and v_status='1'";
$database->setQuery($sql);
$rows = $database->loadObjectList();
$list="";
if($rows){
foreach($rows as $row){
$temp1.='<li><a
href="index.php?new&id='.$row->v_prod_id.'&vid='.$row->v_id.'">'.$row->v_name.'</a></li>';
$temp2.='<li>Rs. '.$row->v_price.'</li>';
}
$list.='<div
class="sliding-box-middle"><ul>'.$temp1.'</ul></div>';
$list.='<div
class="sliding-box-right"><ul>'.$temp2.'</ul></div>';
}else{
$list.='<p>No Variants.</p>';
}
return $list;
}
Below is function used for loading Product Name - for reference
function loadSubCat($id,$Carmodel){
$mainframe =& JFactory::getApplication();
$option = JRequest::getCmd('option');
$database =& JFactory::getDBO();
global $Itemid;
$cond = '';
if($Carmodel!="") {
$cond = " and prod_id='$Carmodel' ";
}
$sql = "Select * from #__newcar_products Where
prod_cat_id='".$id."' $cond and prod_status='1' and prod_id in
(select v_prod_id from #__newcar_variants) Order By
prod_sorder";
$database->setQuery($sql);
$rows = $database->loadObjectList();
$list="";
if($rows){
$flg=0;
foreach($rows as $row){
$temp='<p>'.$row->prod_name.'
<a href="#"
onclick="ShowHide('.$row->prod_id.');
return false;">Select Variant</a>
<div
id="slidingDiv'.$row->prod_id.'"
class="sliding-box">
'.$this->loadProductVarients($row->prod_id).'
</div>
</p>';
if($flg==0){
$list.=''.$temp.'';
$flg=1;
}else{
$list.=''.$temp.'';
$flg=0;
}
}
}else{
$list.='<p>No Product.</p>';
}
return $list;
}

No comments:

Post a Comment