Notice: Trying to access array offset on value of type bool in (7.4.21)

Hello,

I’m making a query like below, but I’m getting this error, what’s wrong here?
Occurs in columns with 0 values
How should I do?

  $transmitter = $db->prepare("SELECT
  transmitter.urun_id,
  transmitter.urun_kac_u,
  rack_kabin_u.u_kac
  FROM transmitter
  INNER JOIN rack_kabin_u ON transmitter.urun_kac_u = rack_kabin_u.id
  WHERE urun_id=? ");
  
    if(isset($_SESSION['transmitter'])){
	// Transmitter ID and Quantity are available in this series.
      $transmitter_array = json_decode($_SESSION['transmitter'], true);
    foreach ($transmitter_array AS $id => $adet){
        $transmitter->execute([$id]);
        $transmitter_u = $transmitter->fetch(PDO::FETCH_ASSOC);
		/*
		The purpose here is to find the total required area 
		by taking how many "U" space this transmitter takes up in 
		the rack cabinet and multiplying the transmitter by amount.
		But this gives error "$transmitter_u['u_kac']"
		*/
        $transmitter_topla += (($transmitter_u['u_kac']+0.50)*$adet);
    }
  }

Your query isn’t returning any results, so ->fetch() returns false. You need your code to do something different is it doesn’t get a result from the database, since obviously you can’t do calculations on nothing.

Thanks for the answer,

There is a result, 0 and numbers are present, no null
This problem occurs in php 7.4 version.
and the problem is not null it gives error for value “0”

We found a solution like below, but I don’t know how accurate it is.

$transmitter = $transmitter_u['u_kac'] ?? '0';
if($transmitter != '0'){
$transmitter_topla += (($transmitter+0.50)*$adet);
}
Sponsor our Newsletter | Privacy Policy | Terms of Service