Notice: Array to string conversion

$Propertypaid = array();
$paid="SELECT t.id, t.year, t.property_id, COALESCE(t.amount,0) AS amount FROM tax_amount t WHERE t.status = 'paid' ORDER BY t.year";
$resultpropertypaid1 = $db->query($paid);
while($row = $resultpropertypaid1->fetch_assoc()){ 
	$Propertypaid[] = $row;
}

$PropertyUnpaid1 = array();
$unpaid1="SELECT 
t.id
, t.year
, t.property_id
, COALESCE(t.amount,0) AS amount 
FROM tax_amount t 
WHERE t.status = 'unpaid' 
ORDER BY t.year";
$resultpropertyunpaid1 = $db->query($unpaid1);
while($row = $resultpropertyunpaid1->fetch_assoc()){ 
	$PropertyUnpaid1[] = $row;
} 


$PropertyUnpaid2 = array();
$unpaid2="SELECT 
  t.id
, t.year
, COALESCE(t.amount,0) AS amount  
, p.block_lot_no
, p.full_name
, p.property_type
, p.location 
FROM tax_amount t   	
	LEFT JOIN property p 
		ON p.id = t.property_id
WHERE t.status = 'unpaid'
ORDER BY t.year";
$resultpropertyunpaid2 = $db->query($unpaid2);
while($row = $resultpropertyunpaid2->fetch_assoc()){ 
	$PropertyUnpaid2[] = $row;
}


$PropertyUnpaid3 = array();
$unpaid3="SELECT 
  t.id
, t.year
, COALESCE(t.amount,0) AS amount
, COALESCE(SUM(pa.amount_paid),0) AS amount_paid		
, ABS(COALESCE(t.amount,0) - COALESCE(SUM(pa.amount_paid),0)) AS amount_due	
, p.block_lot_no
, p.full_name
, p.property_type
, p.location 
FROM tax_amount t 
	LEFT JOIN payments pa 
		ON pa.tax_amount_id = t.id 	
	LEFT JOIN property p 
		ON p.id = t.property_id
WHERE t.status = 'unpaid'
GROUP BY t.id
ORDER BY t.year";
$resultpropertyunpaid3 = $db->query($unpaid3);
while($row = $resultpropertyunpaid3->fetch_assoc()){ 
	$PropertyUnpaid3[] = $row;
}
<a href="#" style="text-decoration:none;color:black;">
	Paid Property:
	<span class="badge pull pull-center"><?php echo $Propertypaid; ?></span>	
</a>
<br>
<a href="#" style="text-decoration:none;color:black;">
	Unpaid Property1:
	<span class="badge pull pull-center"><?php echo $PropertyUnpaid1; ?></span>	
</a>
<br>
<a href="#" style="text-decoration:none;color:black;">
	Unpaid Property2:
	<span class="badge pull pull-center"><?php echo $PropertyUnpaid2; ?></span>	
</a>
<br>
<a href="#" style="text-decoration:none;color:black;">
	Unpaid Property3:
	<span class="badge pull pull-center"><?php echo $PropertyUnpaid3; ?></span>	
</a>
<br>
> [Paid Property:
**Notice** : Array to string conversion in **C:\xampp\htdocs\try\admin\dashboard.php** on line **181**
Array](http://localhost/try/admin/dashboard.php#)
[Unpaid Property1:
**Notice** : Array to string conversion in **C:\xampp\htdocs\try\admin\dashboard.php** on line **186**
Array](http://localhost/try/admin/dashboard.php#)
[Unpaid Property2:
**Notice** : Array to string conversion in **C:\xampp\htdocs\try\admin\dashboard.php** on line **191**
Array](http://localhost/try/admin/dashboard.php#)
[Unpaid Property3:
**Notice** : Array to string conversion in **C:\xampp\htdocs\try\admin\dashboard.php** on line **196**
Array](http://localhost/try/admin/dashboard.php#)

What is it you don’t understand?

1 Like
	<span class="badge pull pull-center"><?php echo $Propertypaid; ?></span>	

	<span class="badge pull pull-center"><?php echo $PropertyUnpaid1; ?></span>	

	<span class="badge pull pull-center"><?php echo $PropertyUnpaid2; ?></span>	

	<span class="badge pull pull-center"><?php echo $PropertyUnpaid3; ?></span>	

You can’t do this…they’re not strings.

Try PHP Type casting

You can’t echo an array, you have to make it a string somehow.
How you do that will depend on the context of your use case.
But for example, you may iterate through the array with a loop:-

foreach($array as $thing){ echo "<p>$thing</p>" ;}

You may echo a specific entity from the array: echo $array[$key];
You may implode a whole array into a string: echo implode(', ', $array);
It depend on what you want to do.

4 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.