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 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理