代码之家  ›  专栏  ›  技术社区  ›  suresh

从php中的下拉列表中删除重复值

  •  1
  • suresh  · 技术社区  · 7 年前

    嗨,我正在尝试从下拉列表中删除重复值。但不知怎的我不知道该怎么做。

     /**
         * Get order ticket details
         */
        public function ticketDetailsAction()
        {
            $orderId = $this->getRequest()->getParam('orderId', 0);
            $contactId = $this->getRequest()->getParam('contactId', 0);
            $bootstrap = $this->getInvokeArg('bootstrap');
            $ticketService = new Tickets_Service_Ticket($bootstrap->getOptions());
            $userId = $this->getUserInfo()->getId();
            $params = array(
                'depotAndAffiliateIds' => array_keys($this->_affiliatedDepotMastersWithActiveDepot),
                'orderId' => $orderId,
                'contactId' => (int)$contactId,
                'user' => $userId,
            );
            $options = array(
                'language' => BAS_Shared_Model_Ticket::LANGUAGE_DEFAULT,
                'user' => $userId,
                'translate' => $bootstrap->getResource('translate'),
                'config' => $bootstrap->getResource('config'),
            );
            $ticketGridService = new Ticket_Service_Grid($ticketService, $options);
            if (0 < (int)$contactId) {
                $this->view->ticketGridObject =  $ticketGridService->getGrid(Ticket_Service_Grid::GRID_TYPE_ORDERTICKETOVERVIEW, $params);
            }
            if (empty($this->view->ticketGridObject)) {
                $where = array('depot_id in (?)' => array_keys($this->_affiliatedDepotMastersWithActiveDepot));
                $this->view->ticketSources = $ticketService->getTicketSourceList($where);
            }
        }
    
    
     /**
     * Get ticket source list
     * 
     * @param array $whereCondition
     * @return array
     */
    public function getTicketSourceList($whereCondition = array())
    {
        /** @var BAS_Shared_Model_TicketSourceMapper  */
        $ticketSource = $this->getMapper('TicketSource');
    
        return $ticketSource->findAllByCondition($whereCondition, 'source ASC');
    }
    
     /**
     * @param string|array|Zend_Db_Table_Select|null $where
     * @param string|array|null $order
     * @param int|null $count
     * @param int|null $offset
     * @return array|BAS_Shared_Model_AbstractModel[]
     */
    public function findAllByCondition($where = null, $order = null, $count = null, $offset = null)
    {
        $rows = $this->getDao()->fetchAll($where, $order, $count, $offset);
        $models = [];
    
        while(($row = $rows->current()) !== null) {
            $models[] = $this->mapRow($row);
            $rows->next();
        }
    
        $this->resetMapToModel();
    
        return $models;
    }
    

    以下是我的观点:

    <select id="ticketSource">
            <option value="">--<?php echo $this->translate('select') ?>--</option>
            <?php foreach ($this->ticketSources as $ticketSource) : ?>
                <option value="<?php echo $ticketSource->source ;?>"><?php echo $ticketSource->source;?></option>
            <?php endforeach;?>
        </select>
    

    有人能帮我吗

    提前谢谢。

    0 回复  |  直到 7 年前