Automatically Generated Tables not generating quite right
Posted: Tue Apr 21, 2009 4:25 pm
I've been working on a function to add to my database classes in order to format the output. The function mostly works, but when it comes to adding actions / links to the tables, for some odd reason it refuses to start at the first row in the system.
This is the entire function:
I have highlighted the start and finish of the problem area with Bold - but the rest of it works just fine.
This is the actual table itself:
Users can link to their own profiles, this is just something to allow other people to view their profiles.
This is the entire function:
Code: Select all
function displayAsTables() {
// echo $this->_sql;
$sql = mysql_query($this->_sql);
if (mysql_num_rows($sql) == 0) {
echo "No results found";
return;
}
echo "<table border='2' tablecolor=black>\n<tr>\n";
$fieldCount = mysql_num_fields($sql);
for ($i = 0; $i < $fieldCount; $i++) {
echo "<th>" . mysql_field_name($sql, $i) . "</th>\n";
}
[b] echo "<th>Links</th></tr>\n";[/b]
while ($row = mysql_fetch_array($sql)) {
echo "<tr>\n";
for ($i = 0; $i < $fieldCount; $i++) {
echo "<td>" . htmlentities($row[$i]) . "</td>\n";
}
$action = str_replace("username", $row[0], $actions);
$actions = '<a href="index.php?option=com_user&view=user&Itemid=68&extuser=username">Profile</a>';
echo "<td nowrap> $action</td>\n</tr>\n";
[b] }[/b]
echo "</table>";
This is the actual table itself:

Users can link to their own profiles, this is just something to allow other people to view their profiles.