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 !!
Edit
Hello Lodder,
Original Function
function loadProductVarients($id,$minprice,$maxprice,$fuel_type){
$mainframe =& JFactory::getApplication();
$option = JRequest::getCmd('option');
$database =& JFactory::getDBO();
global $Itemid;
$Vcond="";
if($minprice!="" and $maxprice!=""){
$Vcond.=" and (v_price between ".$minprice." and ".$maxprice.")";
}elseif($minprice){ $Vcond.=" and v_price >= ".$minprice."";
}elseif($maxprice){ $Vcond.=" and v_price <= ".$maxprice."";}
if($fuel_type!="")
$Vcond.=" and v_fuel_type='$fuel_type' ";
$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){
if($row->v_small_img!=""){
$img = "uploads/variants/".$row->v_big_img ;
}else{
$img="templates/pioneer_home/images/dvd1.jpg";
}
$temp1.='<li><a href="index.php?newcar&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;
}
$sql = "Select * from #__newcar_variants Where v_prod_id='".$id."' $Vcond and v_status='1'";
Below is the modified code as advised written with changes :-
function loadProductVarients($id,$minprice,$maxprice,$fuel_type){
$db = JFactory::getDBO();
$Vcond="";
if($minprice!="" and $maxprice!=""){
$Vcond.=" and (v_price between ".$minprice." and ".$maxprice.")";
}elseif($minprice){ $Vcond.=" and v_price >= ".$minprice."";
}elseif($maxprice){ $Vcond.=" and v_price <= ".$maxprice."";}
if($fuel_type!="")
$Vcond.=" and v_fuel_type='$fuel_type' ";
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__newcar_variants');
$query->where($db->quote($Vcond), $db->quote($id), $db->quote('v_status=1'));
$db->setQuery($query);
$rows = $db->loadObjectList();
$list="";
if($rows){
foreach($rows as $row){
if($row->v_small_img!=""){
$img = "uploads/variants/".$row->v_big_img ;
}else{
$img="templates/pioneer_home/images/dvd1.jpg";
}
$temp1.='<li><a href="index.php?newcar&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;
}