Help! Trying to build mySQL auto-table output
Posted: Fri May 08, 2009 1:30 am
I have a website that is requiring several display tables, and thus far I have one auto-output class ready - but the problem is, it already needs to be modified. I'm running Joomla with a -lot- of custom code on top and placed into it's libraries. This is the current class as-is:
_sql pulls the query for processing for each time it's needed. What I'm trying to do is modify it for paged output, and also to display an image after the first column - so that's two extra classes required. The problem is, I have no clue how to change it. A friend of mine helped create the code itself, from my first attempt which was pretty horrible and bugged. What should I do?
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";
}
echo "<th>Links</th></tr>\n";
while ($row = mysql_fetch_array($sql)) {
echo "<tr>\n";
for ($i = 0; $i < $fieldCount; $i++) {
echo "<td>" . htmlentities($row[$i]) . "</td>\n";
}
$actions = '<a href="index.php?option=com_jumi&fileid=3&extuser=username">Profile</a>';
$action = str_replace("username", $row[0], $actions);
echo "<td nowrap> $action</td>\n</tr>\n";
}
echo "</table>";
}
}