Function on Joomla 3.10 with php 7.4 working but in with php 8.0 Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Post Reply
mch79
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Wed Jul 22, 2015 7:25 am

Function on Joomla 3.10 with php 7.4 working but in with php 8.0

Post by mch79 » Wed Nov 23, 2022 7:01 am

In Joomla 3.10. 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

Code: Select all

    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>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">Price</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

Code: Select all

  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

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 15261
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Function on Joomla 3.10 with php 7.4 working but in with php 8.0

Post by toivo » Wed Nov 23, 2022 8:45 am

mch79 wrote:
Wed Nov 23, 2022 7:01 am
if no brand is selected then all brands in database should be shown instead of No Category as result
The reason is the following line:

Code: Select all

    		if($brand=""){
It is not a comparison but an assignment and therefore always true. The following line should do what you want:

Code: Select all

    		if($brand === "") {
- or simply:

Code: Select all

    		if(!$brand) {
Last edited by toivo on Wed Nov 23, 2022 10:42 am, edited 1 time in total.
Reason: typo
Toivo Talikka, Global Moderator

mch79
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Wed Jul 22, 2015 7:25 am

Re: Function on Joomla 3.10 with php 7.4 working but in with php 8.0

Post by mch79 » Wed Nov 23, 2022 4:22 pm

Awesome, thanks, works like a charm.


Post Reply

Return to “Joomla! 3.x Coding”