Saya rasa inilah yang Anda butuhkan:
Dengan asumsi nama tabel Anda menjadi "pesanan" [tolong ubah sesuai]
$q="show columns from orders";
$res=mysql_query($q) or die(mysql_error());
$arr_field=array();
while($row=mysql_fetch_object($res)){
$field=$row->Field;
$q1="select ".$field." from orders where ".$field."!=0"; //if string then '0'
$res1=mysql_query($q1) or die(mysql_error());
if(mysql_num_rows($res1)>0){
$arr_field[]=$field;
}
}
$q="select ";
foreach($arr_field as $field){
$q.=$field.",";
}
$q=rtrim($q,",");
$q.=" from orders";
$res=mysql_query($q) or die(mysql_error());
while($row=mysql_fetch_object($res)){
foreach($arr_field as $field){
print($field."==".$row->$field."<br/>");
}
}
Jalankan ini dan saya harap Anda akan mendapatkan ide...