php - How do I omit record that contain zeros in certain fields? -
i have query prints records database not understand how omit records contain zeros fields. fields may contain zeros townhalls, org_pressconf, rep_doors, vol_doors, contacts, phones, coffeehours, newsarticles, , mediahits. if each of fields mentioned above equal zero, how write query omit results?
// start organizer report // sending query $result = mysql_query("select concat(last_name, ' , ', first_name) representative, sum(townhalls) townhalls, sum(org_pressconf) pressconference, sum(rep_doors) repdoors, sum(vol_doors) volunteerdoors, sum(contacts) contacts, sum(phones) phones, sum(coffeehours) coffeehours, sum(newsarticles) newsarticles, sum(mediahits) mediahits reports join representatives on reports.rep = representatives.id join users on reports.username = users.username date between '$from' , '$to' , role = 'organizer' group representative order representative;"); if (!$result) { die("query show fields table failed"); } $fields_num = mysql_num_fields($result); echo "<h2>organizer report <small>($from $to)</small></h2>"; echo "<table border='1' cellspacing='0' cellpadding='3' cellspacing='0' cellpadding='3'> <tr>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row array... foreach( .. ) puts every element // of $row $cell variable foreach($row $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); echo "</table>\n"; // end organizer report
add following having clause if want omit rows of fields equal zero.
having (townhalls + org_pressconf + rep_doors + vol_doors + contacts + phones + coffeehours + newsarticles + mediahits) > 0
Comments
Post a Comment