I have added the functionality to my store to show the items that 
have been added since a certain date.  I thought I'd share it if 
anyone was interested.  It's very simple, I haven't put in any error 
checking, and it's probably fairly inefficient because it calls 
GetItemInfo over and over but it's quick and dirty.  Although in my 
testing it is returning 400+ items and really isn't that slow.  

Also I have not done extensive testing to ensure that adding a field 
to the item table doesn't cause errors elsewhere.  I was able to 
view an item but I didn't try any of the admin functions.

Here's how to do it:

1) Add a column to the item table.  The SQL is:
ALTER TABLE item ADD COLUMN DateAdded DATETIME NOT 
NULL

2) This step is optional.  By putting the NOT NULL in the previous 
step all items that were in the table already have a DateAdded of 
'0000-00-00 00:00:00'.  If you want, set DateAdded to the current 
time with this SQL statement:
UPDATE item SET DateAdded=NOW()

3) Add this function to item_functions.  The parameter should be in 
a date format mysql understands so it can be compared to the 
DateAdded column.  The function returns a 2-dimensional array: 
the first dimension is just the index of items (0,1,2, etc.) and the 
second dimension is the array that GetItemInfo returns (ID, Name, 
Description, etc.)
        function GetNewItems($NewItemDate) {
                global $DatabaseLink;   

                $Query = "SELECT ID ";
                $Query .= "FROM item ";
                $Query .= "WHERE DateAdded > '" . $NewItemDate . "' ";
                $Query .= "AND Active = 'Y'";
                $DatabaseResult = mysql_query($Query, $DatabaseLink);
                
                while ($row = mysql_fetch_array($DatabaseResult)) {
                        $NewItem[] = GetItemInfo($row["ID"]);                   
                }
                return($NewItem);
        }

4) Now just make sure wherever you are adding items to the 
database that you use NOW() to fill in the DateAdded column.

Example usage:
This example prints a list of the names of the items that have been 
added since the 1st of the current month.

$NewItems = array();
$NewItems = GetNewItems(date("Y-m-d", mktime(0,0,0,date("m")-
1,0,date("Y"))));
for ($x=0;$x<count($NewItems);$x++) {
        print $NewItems[$x]["Name"] . "<BR>";
}


Very simple.  The hardest part is dealing with the lack of date 
functions in php. *sigh*


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

Reply via email to