I have created a function where query displaying database models correctly when chosen, however if no model selected then i want query to display entire list of models
I mean have database as
id
cat_name
cat_sorder for ascending or descending order
state
Here cat_name has different car manufacturers as Honda Tesla Hyundai Suzuki Ford VW etc
Now when in created function and choosing brand as say Tesla then its displaying correctly as tesla. But if i am not choosing any brand then its displaying 'No Category as shown in last line' which i want to change to display 'entire list of car brands.
Surprise Elememt - this function working perfectly fine when php version changed to php 7.4, but in php 8.0 is not working as desired
public function loadMainCat($brand,$Carmodel){
$mainframe =JFactory::getApplication();
$db = JFactory::getDBO();
$query = $db->getQuery(true);
if($brand!=""){
$query = "Select * from #__newcar_categories Where id ='".$brand."' and state='1' Order By cat_sorder ";
}else{
$query = "Select * from #__newcar_categories Where 1 and state='1' Order By cat_sorder ";
}
$db->setQuery($query);
$rows = $db->loadObjectList();
$list="";
$flg=0;
if($rows){
$id='';
$Desc=$this->loadSubCatDescr($id);
$list.='<div class="listing-box">
<div class="listing-box-left">
<h4>Car Make</h4>
</div>
<div class="listing-box-middle">
<h4> Model</h4>
</div>
<div class="listing-box-right">
<h4><a href="#" onMouseover="ddrivetip(\'Ex-Showroom Delhi\')"; onMouseout="hideddrivetip()" style="color:#424141">Base Price Delhi</a></h4>
</div>';
foreach($rows as $row){
$item_id = $this->getItemIdByName($row->cat_name);
if($row->cat_image!=""){
$img = "uploads/categories/".$row->cat_image;
}
if($flg==0){
$cls="";
$flg=1;
}else{
$cls="";
$flg=0;
}
$list.='<div class="listing-box-left"><p>'.$row->cat_name.'</p></div>
<div class="listing-box-middle">'.$this->loadSubCat($row->id,$Carmodel).'</div>';
}
$list.='</div>';
}else{
$list.='<div class="listing-box">No Category.</div>';
}
return $list;
}
Now, If i modify function in this way where value of if($brand!="") changed to if($brand="")
then yes then in event of no brand as selected, its displaying all brands, but even if select brand as Tesla then still its displaying all brands
public function loadMainCat($brand,$Carmodel){
$mainframe =JFactory::getApplication();
$db = JFactory::getDBO();
$query = $db->getQuery(true);
if($brand=""){
$query = "Select * from #__newcar_categories Where id ='".$brand."' and state='1' Order By cat_sorder ";
}else{
$query = "Select * from #__newcar_categories Where 1 and state='1' Order By cat_sorder ";
}
$db->setQuery($query);
$rows = $db->loadObjectList();
$list="";
$flg=0;
if($rows){
$id='';
$Desc=$this->loadSubCatDescr($id);
$list.='<div class="listing-box">
<div class="listing-box-left">
<h4>Car Make</h4>
</div>
<div class="listing-box-middle">
<h4> Model</h4>
</div>
<div class="listing-box-right">
<h4><a href="#" onMouseover="ddrivetip(\'Ex-Showroom Delhi\')"; onMouseout="hideddrivetip()" style="color:#424141">Base Price Delhi</a></h4>
</div>';
foreach($rows as $row){
$item_id = $this->getItemIdByName($row->cat_name);
if($row->cat_image!=""){
$img = "uploads/categories/".$row->cat_image;
}
if($flg==0){
$cls="";
$flg=1;
}else{
$cls="";
$flg=0;
}
$list.='<div class="listing-box-left"><p>'.$row->cat_name.'</p></div>
<div class="listing-box-middle">'.$this->loadSubCat($row->id,$Carmodel).'</div>';
}
$list.='</div>';
}else{
$list.='<div class="listing-box">No Category.</div>';
}
return $list;
}
Pls help on how to achieve that
If a brand is selected as showing in original function then correct brand is shown, but if no brand is selected then all brands in database should be shown instead of No Category as result
Thanks