Page 1 of 1

Help! Trying to build mySQL auto-table output

Posted: Fri May 08, 2009 1:30 am
by Teonnyn
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:

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>&nbsp;$action</td>\n</tr>\n";
    }
    echo "</table>";
 
       }
}
 
_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?

Re: Help! Trying to build mySQL auto-table output

Posted: Sat May 09, 2009 1:16 pm
by Teonnyn
Still unsolved so requesting help on this again! I may have found a way to do the paging, so no actual problem there after all, however haven't worked out the avatar display yet.