3

display of the last 30 days with the table data

 3 years ago
source link: https://www.codesd.com/item/display-of-the-last-30-days-with-the-table-data.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

display of the last 30 days with the table data

advertisements

I have a table of records that has a column with the created_date. I am looking for a way to display these records by date broke out in day sections. So Today would show only records that were added today and then underneath that table that shows yesterday with only yesterdays records. I am sure it is an array of some sort and may be simpler than i am making it out to be but i have looked at some loops and cant piece it together. Tried this but not sure how to use it to populate the records.

for ($i = 0; $i < 30; i++)
{
$timestamp = time();
$tm = 86400 * $i; // 60 * 60 * 24 = 86400 = 1 day in seconds
$tm = $timestamp - $tm;

$the_date = date("m/d/Y", $tm);
}

also since written in Zend i need proper stuff in the controller, model, view. I think the view is what i am stuck on. the model is just going to retrieve data by date. Thanks for the help!

Updated 10:27 9-25-2012 This is the controller for the view

    public function detailsAction()
{
    $request   = $this->getRequest();
    $setId     = $request->getParam('set_id');
    $pageIndex = $request->getParam('page_index', 1);
    $perPage = 15;
    $offset  = ($pageIndex - 1) * $perPage;

    $conn = XXX_Db_Connection::factory()->getSlaveConnection();
    $setDao  = XXX_Model_Dao_Factory::getInstance()->setModule('media')->getSetDao();
    $photoDao = XXX_Model_Dao_Factory::getInstance()->setModule('media')->getPhotoDao();
    $setDao->setDbConnection($conn);
    $photoDao->setDbConnection($conn);

    $set = $setDao->getById($setId);
    if (null == $set) {
        throw new XXX_Exception_NotFound();
    }

    /**
     * Get the list of photo that belongs to this set
     */
    $photos       = $photoDao->getPhotosInSet($setId, $offset, $perPage, true);
    $numPhotos = $photoDao->countPhotosInSet($setId, true);

    /**
     * Paginator
     */
    $paginator = new Zend_Paginator(new XXX_Utility_PaginatorAdapter($photos, $numPhotos));
    $paginator->setCurrentPageNumber($pageIndex);
    $paginator->setItemCountPerPage($perPage);

    $this->view->assign('set', $set);
    $this->view->assign('photos', $photos);

    $this->view->assign('paginator', $paginator);
    $this->view->assign('paginatorOptions', array(
        'path'     => $this->view->url($set->getProperties(), 'media_set_details'),
        'itemLink' => 'page-%d',
    ));
}

here are the associated models

    public function getById($id)
{
    $sql = sprintf("SELECT * FROM " . $this->_prefix . "media_set
                    WHERE set_id = '%s'
                    LIMIT 1",
                    mysql_real_escape_string($id));
    $rs  = mysql_query($sql);
    $return = (0 == mysql_num_rows($rs)) ? null : new Media_Models_Set(mysql_fetch_object($rs));
    mysql_free_result($rs);
    return $return;
}

    public function getPhotosInSet($setId, $offset = null, $count = null, $isActive = null)
{
    $sql = sprintf("SELECT * FROM " . $this->_prefix . "media_photo AS f
                    INNER JOIN " . $this->_prefix . "media_photo_set_assoc AS fs
                        ON fs.photo_id = f.photo_id AND fs.set_id = '%s'",
                    mysql_real_escape_string($setId));
    if (is_bool($isActive)) {
        $sql .= sprintf(" WHERE f.is_active = '%s'", (int)$isActive);
    }
    $sql .= " ORDER BY f.photo_id DESC";
    if (is_int($offset) && is_int($count)) {
        $sql .= sprintf(" LIMIT %s, %s", $offset, $count);
    }

    $rs   = mysql_query($sql);
    $rows = array();
    while ($row = mysql_fetch_object($rs)) {
        $rows[] = $row;
    }
    mysql_free_result($rs);
    return new XXX_Model_RecordSet($rows, $this);
}

public function countPhotosInSet($setId, $isActive = null)
{
    $sql = sprintf("SELECT COUNT(*) AS num_photos FROM " . $this->_prefix . "media_photo AS f
                    INNER JOIN " . $this->_prefix . "media_photo_set_assoc AS fs
                    ON fs.photo_id = f.photo_id AND fs.set_id = '%s'",
                    mysql_real_escape_string($setId));
    if (is_bool($isActive)) {
        $sql .= sprintf(" WHERE f.is_active = '%s'", (int)$isActive);
    }
    $sql .= " LIMIT 1";
    $rs   = mysql_query($sql);
    $row  = mysql_fetch_object($rs);
    mysql_free_result($rs);
    return $row->num_photos;
}

Updated 09/26/2012 - Added new method

I have added this to my view it displays the date as headers like i want however it prints duplicates also. I am looking to group them under the date:

This is the view:

<?php if ($this->sets) : ?>
<div class="t_media_list_sets">
<h2><?php echo $this->translator()->widget('title'); ?></h2>

<ul>
    <?php foreach ($this->sets as $set) : ?>
    <?php $curDate = 0; ?>
    <?php $date = $set->created_date; ?>
    <?php if ($date != $curDate) : ?>
        <?php $curDate = $date; ?>
        <?php echo  $curDate; ?>
    <?php endif; ?>

    <li>
        <a href="<?php echo $this->url($set->getProperties(), 'media_set_details'); ?>">
            <?php echo $set->title; ?>
        </a>
        <?php echo $set->description; ?>
    </li>
    <?php endforeach; ?>
</ul>

<div class="clearfix"></div>
</div>
<?php endif; ?>

Here is the model i am using: Ignore previous models shown, i created a widget

    public function setlist($offset = null, $count = null, $exp = null)
{
    $sql = "SELECT * FROM " . $this->_prefix . "media_set AS s";
    if ($exp) {
        $where = array();

        if (isset($exp['created_user_id'])) {
            $where[] = sprintf("s.created_user_id = '%s'", mysql_real_escape_string($exp['created_user_id']));
        }
        if (isset($exp['keyword'])) {
            $where[] = "s.title LIKE '%" . addslashes($exp['keyword']) . "%'";
        }
        if (isset($exp['is_active'])) {
            $where[] = sprintf("s.is_active = '%s'", (int)$exp['is_active']);
        }

        if (count($where) > 0) {
            $sql .= " WHERE " . implode(" AND ", $where);
        }
    }
    $sql .= " ORDER BY s.created_date DESC";
    if (is_int($offset) && is_int($count)) {
        $sql .= sprintf(" LIMIT %s, %s", $offset, $count);
    }

    $rs   = mysql_query($sql);
    $rows = array();
    while ($row = mysql_fetch_object($rs)) {
        $rows[] = $row;
    }
    mysql_free_result($rs);
    return new XXX_Model_RecordSet($rows, $this);
}


<?php
$d = array();
for($i = 0; $i < 30; $i++)
    $d[] = date("d", strtotime('-'. $i .' days'));
?>

Also Refer this link for such type of operations

http://www.vision.to/how-to-add-days-weeks-months-to-any-date-.php


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK