<?php
// Connect to the database
$db = new PDO('mysql:host=localhost;dbname=my_database', 'username', 'password');
// Get the data from the database
$sql = 'SELECT * FROM my_table';
$results = $db->query($sql);
// Iterate through the results and exclude columns with 0 value
$filtered_results = [];
foreach ($results as $row) {
$filtered_row = [];
foreach ($row as $key => $value) {
if ($value != 0) {
$filtered_row[$key] = $value;
}
}
$filtered_results[] = $filtered_row;
}
// Print the filtered results
print_r($filtered_results);
?>