Re: Stuffing code into variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Feb 3, 2007, at 9:09 PM, Christopher Weldon wrote:


On Feb 3, 2007, at 9:09 PM, Albert Padley wrote:

It's late and I've been at this a long time today so I throw myself on the mercy of the list.

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?

Thanks.

Al Padley

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



You could always make it a function...ie:

function drawTableRow($sqlRow) {
return "<tr>\n<td class=\"tabletext\">". $sqlRow['time'] ."</td> \n<td class=\"tabletext\">".$row['field']."</td>"; // Simplified for time purposes.
}

// Execute the query
foreach ($row = mysql_fetch_array($query)) {
    echo drawTableRow($row);
}

That's perfect. I should of thought of using a function.

Thanks.

Al

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux