I thought I would share some code that I wrote to split up the items 
into multiple pages.  In my case I am splitting it into 10 items per 
page, in 2 columns, but you can change that to whatever you want 
by changing the vars $NumItemsPerPage, $Rows, and $Cols.

This goes in modules/screens/department, overwriting everything 
from the line "//show items in this department" til the end....the 
stuff I added is highlighted with comments starting with CW

Enjoy!
------------
        //show items in this department
        /* CW - Only show 10 items per screen in a 2x5 table */
        $NumItemsPerPage = 10;
        $Rows = 5;
        $Cols = 2;
        if (!isset($StartItem)) {
                $StartItem = 0;
        }
        /* CW - made 3 query strings so I didn't have to rewrite the
                query for the count :) */
        $Query = "SELECT i.ID, i.Name, i.Thumbnail ";
        $Query2 = "FROM item i, department_item di ";
        $Query2 .= "WHERE di.Department = $department ";
        $Query2 .= "AND i.ID = di.Item ";
        $Query3 = "ORDER BY i.DisplayPrecedence, i.Name ";
        /* CW - add limit */
        $Query3 .= "LIMIT $StartItem, $NumItemsPerPage";
        $DatabaseResult = mysql_query($Query . $Query2 . $Query3, 
$DatabaseLink);
        /* CW - If there are no items in this department don't bother */
        if (mysql_numrows($DatabaseResult)>0) { 
                /* CW - get total number of items */
                $Query = "SELECT count(i.ID) AS Number " . $Query2;
                $Result = mysql_query($Query, $DatabaseLink);
                $TotalNumber = mysql_result($Result, 0, "Number");
                
                /* CW - print Numbers, and Next/Prev Links */
                /* todo: make this a function so I can do it at the top and 
the bottom of the items table */
                print("<BR>\n<TABLE ROWS=1 COLS=3 WIDTH=100% 
BORDER=0>\n");
                print("\t<TR><TD WIDTH=33% ALIGN=\"left\">");
                /* CW - Prev Link if necessary */
                if ($StartItem>0) {
                        print("<A 
HREF=\"".ScreenURL("department")."&department=$department&S
tartItem=" . ($StartItem-$NumItemsPerPage) . "\">Prev</A>");
                }
                print("</TD>\n\t<TD WIDTH=33% ALIGN=\"center\">");
                print("Items " . ($StartItem + 1) . " - " . ($StartItem + 
$NumItemsPerPage) . " of $TotalNumber");        
                print("</TD><TD WIDTH=33% ALIGN=\"right\">");
                /* CW - Next link if necessary */
                if ($TotalNumber>($StartItem+$NumItemsPerPage) ) {
                        print("<A 
HREF=\"".ScreenURL("department")."&department=$department&S
tartItem=" . ($StartItem+$NumItemsPerPage) . "\">Next</a>");
                }
                print("</TD></TR>\n</TABLE>\n<BR>\n");
                /* CW - print a table 2x5 */    
                print("<TABLE ROWS=$Rows COLS=$Cols WIDTH=100% 
BORDER=0>\n");
                $i = 1; 
        /* CW - I was too lazy to indent all this too :)  */    
        while($DatabaseRow = mysql_fetch_object($DatabaseResult))
        {
                if (($i % $Cols) == 1 ) {
                        /* CW - first item, left columm, start a new row */
                        print("\t<TR>\n");
                }
                print("\t\t<TD VALIGN=\"top\">");
                print("<A 
HREF=\"".ScreenURL("item")."&item=$DatabaseRow->ID\">");
                if(($DatabaseRow->Thumbnail) AND 
                        file_exists(ITEM_IMAGES_DIR . "/" . $DatabaseRow-
>Thumbnail))
                {
                        $Thumbnail_Graphic_size = 
getimagesize(ITEM_IMAGES_DIR . "/" . $DatabaseRow-
>Thumbnail);
                        print("<IMG SRC=\"" . ITEM_IMAGES_DIR . "/" . 
$DatabaseRow->Thumbnail . "\"");
                        print(" $Thumbnail_Graphic_size[3] BORDER=\"0\" 
ALIGN=\"left\">\n");
                } else {
                        /* CW - print NoImage holder */
                        print("<IMG SRC=\"" . ITEM_IMAGES_DIR . 
"/NoImage.gif\" WIDTH=100 HEIGHT=99 BORDER=0 
ALIGN=\"left\">\n" );
                }
                print("<B>$DatabaseRow->Name</B>");
                print("</A>");
                print("<BR CLEAR=\"all\">\n");
                print("<BR>\n");
                print("</TD>\n");
                if (($i % $Cols) == 0 ) {
                        /* CW - even-numbered item, right columm, end 
row */
                        print("\t</TR>\n");
                }               
                $i++;
        } //end while
        print("</TABLE>");
        } //end if

?>



------------------------------------------------------------
To subscribe:    [EMAIL PROTECTED]
To unsubscribe:  [EMAIL PROTECTED]
Site:            http://www.working-dogs.com/freetrade/
Problems?:       [EMAIL PROTECTED]

Reply via email to