Re: Stuffing code into variable
| From: | Albert Padley | Date: | Sun, 04 Feb 2007 06:05:49 +0000 |
| Subject: | Re: Stuffing code into variable | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248272@lists.php.net to get a copy of this message | ||
On Feb 3, 2007, at 10:04 PM, Paul Novitski wrote:
As far as the CSS on the <td>, other cells in the table have different styling. AlOn Feb 3, 2007, at 9:09 PM, Albert Padley wrote:At 2/3/2007 08:09 PM, Christopher Weldon wrote:I have an echo statement that I use in conjunction with a MySQL query. echo "<tr>\n<td class=\"tabletext\">" . $row['time'] . "</td>\n<td class=\"tabletext\">" . $row['field'] . "</td>\n<td class= \"tabletext\">" . $row['division'] . "</td>\n"; This works perfectly fine. However, I will be using the same code numerous times on the page and wanted to stuff it all into a variable. At this point I can't remember the proper syntax and quoting to get this right. Any takers?You could always make it a function...ie: function drawTableRow($sqlRow) {Good suggestion. I like heredoc's clean presentation: __________________________________ function drawTableRow($sqlrow) {return "<tr>\n<td class=\"tabletext\">". $sqlRow['time'] ."</td> \n<td class=\"tabletext\">".$row['field']."</td>"; // Simplified fortime purposes. }return <<<_<tr><td class="tabletext">{$sqlrow['time']}</td> <td class="tabletext">{$sqlrow['field']}</td> <td class="tabletext">{$sqlrow['division']}</td></tr> _; } __________________________________ By the way, if every cell in every row is class "tabletext" why have a class at all? You could simply apply the desired styles to the td element. Regards, Paul I'm using heredoc elsewhere on the page so that's a good idea.