Help! Trying to build mySQL auto-table output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Teonnyn
Forum Commoner
Posts: 58
Joined: Tue Dec 23, 2008 4:07 am

Help! Trying to build mySQL auto-table output

Post 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?
Last edited by Benjamin on Fri May 08, 2009 9:38 am, edited 1 time in total.
Reason: Changed code type from text to php.
Teonnyn
Forum Commoner
Posts: 58
Joined: Tue Dec 23, 2008 4:07 am

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

Post 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.
Post Reply