SunQuest
 
       Database Code
  Home arrow Database Code arrow Table Drawer (Powerful table dumper)
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE CODE

Table Drawer (Powerful table dumper)
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-09-18

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    This is a script that you include into your file. It will draw a table for you. It's features include every-column sortable (asc/desc), multi-categories. I made this to be able to output tables quickly. Also, with a centralized drawing script, I can change the "theme" of my site easier, without using a real theme engine.

    Eg usage I use to output the different topics on my forum:
    $perpage = 15;
    $columns = array("title"=>"Topic", "numofposts"=>"numofposts", "lastpost"=>"Last post");
    $spacerColumn = "category";
    $spacerColumnSort = "$tables->categories.sortfromleft asc";
    $spacerLabel = '
    $row[categoryname]';
    $columnsDisplay = array("title"=>'"".$row["title"].""', "lastpost"=>'$row[lastupdated] . "->"');
    $defaultSort="sortOrder desc";
    $baseSQL = "select *, category as category, DATE_FORMAT($tables->forumTopics.lastupdated, \"%c-%e-%y at %r\") as lastupdated, $tables->forumTopics.id as id from $tables->forumTopics, $tables->categories where $tables->forumTopics.category=$cat and $tables->forumTopics.hidden=0 and $tables->forumTopics.category=$tables->categories.id";

    By : webhappy

    <?php

    /*
    To use, set the following variables as shown:
    $perpage = 5;
    $showPageChoice=1;
    $columns = array("thread"=>"thread link", "member"=>"member name");
    $spacerColumn; //will add a space between rows that do not have the same value in spacerColumn, used mainly for the forums
    $columnsPre; //array that is similar in structure to columnsDisplay, but this one is eval'd BEFORE the display one, the dislpay one is echo'd
    $columnsDisplay = array("member"=>"<a href=$SITE_ROOT/viewuser.html?id=".$row["member"].">".$row["member"]."</a>");
    $defaultSort;
    $baseSQL = "select * from $tables->forumMessages";

    //NOTE! the columns array goes like this: REAL column name => description
    //Hides your column names for more protection against SQL attacks
    //hides your table names too
    */


    if ( empty($page) ) {$page = 1;}

    $finalSQL = $baseSQL;

    if ( isset($spacerColumnSort) )
    {
    $finalSQL .= " order by " . $spacerColumnSort;
    $orderSyntaxStarted=true;
    }

    if ( !empty($sort) )
    {
    if ( !in_array($sort, $columns) )
    finalizeAndDie("Invalid sort key specified; Hack attempt of type SQL-injection has been logged");

    $temp =array_keys($columns, $sort);

    if ( $orderSyntaxStarted )
    $finalSQL .= ",". $temp[0];
    else
    $finalSQL .= " order by " . $temp[0];

    $sortFlags = $sortflags;
    if ( $sortFlags == "reverse" )
    $finalSQL .= " desc";

    }
    else if ( isset($defaultSort) )
    if ( $orderSyntaxStarted )
    $finalSQL .= "," . $defaultSort;
    else
    $finalSQL .= " order by " . $defaultSort;

    $finalSQL .= " limit " . $perpage * ($page-1) . "," . $perpage;
    $saveFinalSQL = $finalSQL;
    //echo $finalSQL . '<hr>';
    $finalSQL = mysql_query($finalSQL);

    $total = mysql_query($baseSQL);
    $sqlcount = mysql_num_rows($total);
    $pagemin = ceil($sqlcount / $perpage);

    $choosepage = "Pages: ";
    for ( $n=1; $n <= $pagemin; $n++ )
    {
    if ( $n > 1 )
    $choosepage .= " ";

    if ( $n == $page )
    $choosepage .= "<b>$n</b>";
    else
    $choosepage .= "<a href='$_SERVER[PHP_SELF]?page=$n&sort=".addslashes($sort)."&sortFlags=$sortFlags'>$n</a>";
    }





    if ( $showPageChoice == 1)
    echo $choosepage;

    //echo "</p>";

    $keep="";
    if ( isset($keepStatic) )
    {
    foreach ( $keepStatic as $t )
    $keep .= "$t={$$t}";

    $keep .= "&";
    }

    echo "<table border=0 cellpadding= cellspacing=5>";
    $i=0;
    foreach ( $columns as $t )
    {
    if ( $t == $sort && $sortFlags != "reverse" )
    $temp = "&sortflags=reverse title='Click to sort in descending order by ".addslashes($t)."'";
    else
    $temp = " title='Click to sort in ascending order by ".addslashes($t)."'";
    echo "<th>&nbsp;<a href=$_SERVER[PHP_SELF]?{$keep}sort=".urlencode($t).$temp.">$t</a>&nbsp;</th>";
    }

    $i=0;
    while ( $row = mysql_fetch_array($finalSQL) )
    {
    if ( isset($spacerColumn) )
    {
    if ( $row[$spacerColumn] != $spacerTracker || !isset($spacerTracker) )
    {
    $i=0;
    echo "<tr><td colspan=".sizeof($columns).">";
    //echo $spacerLabel;

    $spacerEval = 'echo "' . $spacerLabel . '";';
    eval ($spacerEval);

    echo " &nbsp; </td></tr>";
    }

    $spacerTracker=$row[$spacerColumn];
    }

    if ( $i++ % 2 == 0 )
    echo "<tr bgcolor=B0C4DE>";
    else
    echo "<tr bgcolor=FOF8FF>";

    foreach ( array_keys($columns) as $t )
    {
    echo "<td>";

    if ( isset($columnsPre[$t]) )
    {
    //echo $columnsPre[$t];
    eval($columnsPre[$t]);
    }


    if ( isset($columnsDisplay[$t]) )
    {
    eval("echo ".$columnsDisplay[$t].";");
    }
    else
    echo $row[$t];
    echo "</td>";
    }

    echo "</tr>";
    }
    echo "</table>";

    if ( $showPageChoice == 1)
    echo "</p>" . $choosepage;


    //Unitialize vars, cuz some are optional and if someone calls this page twice on a page, some variables may remain from the first call (and optional ones on teh second one will be set to the first one's settings)
    if ( isset($spacerColumn) ) unset ($spacerColumn);
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Database Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Best practices for software analysis: An introduction to the IBM Rational Software Analyzer application

    This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer.
    FREE! Go There Now!


    NEW! Did you say mainframe? e-kit

    Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise.
    FREE! Go There Now!


    NEW! Download a free trial of Lotus Quickr 8.0

    Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Software Analyzer V7.0

    Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle.
    FREE! Go There Now!


    NEW! Hello World: Learn how to install and use the Rational Asset Manager Eclipse client

    In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset.
    FREE! Go There Now!


    NEW! Maintaining QoS and Process Integrity in an SOA Environment

    This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”.
    FREE! Go There Now!


    NEW! Trial download: IBM Lotus Forms V3.0

    Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Connectivity

    Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic.
    FREE! Go There Now!


    NEW! Webcast: Application security testing and Web compliance

    Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development.
    FREE! Go There Now!


    NEW! Whitepaper: Achieving consistency between business process models and operational guides

    Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    DATABASE CODE ARTICLES

    - Examples and Tools for Database Design
    - Relationships, Entities and Database Design
    - Modeling and Designing Databases
    - Data extract to Excel
    - Oracle database class 0.76
    - The opposite of mysql_fetch_assoc
    - On line Thermal Transmitance Calculation
    - pjjTextBase
    - PHP Object Generator
    - FastMySQL
    - RC4PHP
    - SQL function with integrated sprintf()
    - DB Interaction Classes v1.1
    - deeMySQLParser
    - CSV to SQL convertor






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway