douzhang1926 2015-03-09 21:19
浏览 13
已采纳

如何更新joomla模块或后端中的表?

I working on some module and want to have ability to update table with image sizes - there already two columns in table (width, height). Its my first approach to joomla module develop. All code works except last foreach with update. Where I'm wrong?

And how to trigger this function in module or in backend module settings to button or link? Code in helper.php:

        public static function updateSize( $params )
{
        $app = JFactory::getApplication();
        $doc = JFactory::getDocument();
        JHtml::_('behavior.framework', true);
        $db = JFactory::getDbo();

        $query = $db->getQuery(true)
                        ->select($db->quoteName(array('a.imgfilename', 'b.catpath')))
                        ->from($db->quoteName('#__imagestable', 'a'))
                        ->where(($db->quoteName('height').'=') && ($db->quoteName('width').'='))
                        ->join('INNER', $db->quoteName('#__imagestable_cat', 'b') . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('b.cid') . ')')
                        ->order('RAND() LIMIT 5');

        $db->setQuery($query);
        $size = $db->loadObjectList();
        return $size;

        foreach($size as $imageSize){
            $imgpath = $path.$imageSize->catpath.'/'.$imageSize->imgfilename;
            $imgfilename = $imageSize->imgfilename;
            list($width, $height) = getimagesize($imgpath);
            $validImgs[] = $imageSize;

            foreach ( $validImgs as $row ) {
                    $query = $db->getQuery(true)
                                 ->update($db->quoteName('#__imagestable')) 
                                 ->where ($db->quoteName('imgfilename').'='.$imgfilename)
                                 ->set(array($db->quoteName('height') . '=' . $height, $db->quoteName('width') . '=' .$width));

                     $db->setQuery($query); 
                     $imgSize = $db->execute();
                }
        }
}

Is it possible to attach this function to backend XML - maybe to button "Update image sizes"?

  • 写回答

1条回答 默认 最新

  • dongquming3255 2015-03-10 04:38
    关注

    You are using return $size; before the foreach.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码