random1 Posted December 21, 2007 Share Posted December 21, 2007 My web application currently has a working function that creates a correctly formatted HTML table from a supplied 2D array (results from database) and caption. How can I modify they below code for this logic: * If data field is a link (http:, https:// or ftp://) then create an HTML <a> around field * If data field is a URL to an image then create an HTML <img> around field * If data field is a comma sperated list then create a list box and submit button * Add form buttons to last column with 'edit', 'delete' and a change status select list Function Code: public static function DisplayAsGrid($records, $caption) { $r = ''; //if there is 1 or more if(count($records) > 0) { //start table $r .= '<table summary="Example Summary">'. "\r\n"; if($caption!=""){$r .= '<caption><em>'.$caption.'</em></caption>' . "\r\n";}; //Table Head $r .= '<thead>' . "\r\n"; $r .= '<tr>' . "\r\n"; foreach($records[0] as $key=>$value) { $r .= '<th scope="col" abbr="'.$key.'">' . $key . '</th>' . "\r\n"; } $r .= '</tr>'. "\r\n"; $r .= '</thead>'. "\r\n"; $r .= '<tbody>'. "\r\n"; //Table Footer : ToDo foreach($records as $record) { // Table Fields $r .= '<tr>' . "\r\n"; foreach($record as $field) { $r .= '<td>' . $field . '</td>' . "\r\n"; } $r .= '</tr> ' . "\r\n"; } $r .= '</tbody>'. "\r\n"; //end table $r .= '</table>' . "\r\n"; } return $r; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 21, 2007 Share Posted December 21, 2007 You'll need to use strpos and substr to get the various parts of the string you're looking for. For the CSV question you could use explode. The form buttons sounds simple enough. Do you really not know how to write the HTML or am I misunderstanding? Quote Link to comment Share on other sites More sharing options...
random1 Posted December 21, 2007 Author Share Posted December 21, 2007 I'm mainly wanting to know the functions that I can use to do it quickly and best. Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 21, 2007 Share Posted December 21, 2007 Did you not read my post? Quote Link to comment Share on other sites More sharing options...
random1 Posted December 21, 2007 Author Share Posted December 21, 2007 Yep thanks, Im making progress using those Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.