/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Controller: public function exportAction() { $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $this->tbl = new Contacts(); $xlsTbl = $this->tbl->exportContacts(); echo "<table>$xlsTbl</table>"; } Model: public function exportContacts() { $result = $this->_db->fetchAll('SELECT * FROM contacts'); $xlsTbl = "<tr><th>First Name</th><th>Last Name</th><th>Email</th><th>Region</th><th>Enquiry Type</th><th>Telephone</th><th>Message</th><th>Type</th></tr>"; foreach($result as $key=>$val){ $xlsTbl .= "<tr>"; $xlsTbl .= "<td>" . $val->first_name . "</td>"; $xlsTbl .= "<td>" . $val->last_name . "</td>"; $xlsTbl .= "<td>" . $val->email . "</td>"; $xlsTbl .= "<td>" . $val->region . "</td>"; $xlsTbl .= "<td>" . $val->enquiry_type . "</td>"; $xlsTbl .= "<td>" . $val->telephone . "</td>"; $xlsTbl .= "<td>" . $val->message . "</td>"; $xlsTbl .= "<td>" . $val->type . "</td>"; $xlsTbl .= "</tr>"; } return $xlsTbl; }