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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 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


    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! IBM – Taking Web 2.0 to Work

    David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! A Layered approach to delivering security-rich Web applications

    As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper.
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! Download IBM Data Studio V1.1

    Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms.
    FREE! Go There Now!


    NEW! Hello World: WebSphere Service Registry and Repository

    Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services.
    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! Successful Change and Release Management for .NET

    Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Process

    Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly.
    FREE! Go There Now!


    NEW! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    FREE! Go There Now!


    NEW! Webcast: Calling All Testers! Find Application Vulnerabilities Early in the Development Process Where they are Easier to Fix and Less Risky to your Business

    In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information.
    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-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek