首页 > 解决方案 > 如何从数据库中返回属性

问题描述

我有问题。看看我的功能。向你详细解释一切。第一个仅返回“前”或“后”,具体取决于选择了哪一个。我希望如果没有选择这些,请以这种格式将所有内容从正面和背面返回给我:

array (size=3)
  'breite' => string '110' (length=3)
  'hoehe' => string '70' (length=2)
  'zoll' => string '17' (length=2)

看我的网址:

 http://localhost/ccr/filter?atts[breite]=110&atts[hoehe]=70&atts[zoll]=17&parent=49

通过 url 我发送 attibutes 正面或背面。

我只需要通过 url ,如果正面或背面未选择返回和正面和背面。看看我需要的功能代码:

    if(key_exists('antrieb',$get)) {
        $antrieb = $get['antrieb']; //back or front
        $query = $this->db->query("
            SELECT mo.$antrieb
            FROM " . DB_PREFIX . "model mo
            WHERE mo.id != 0
            $where
        ")->rows;
        $data = []; 
        $size = explode("|", $query[0][$antrieb]);
        $data['atts'] = array(
            'breite' => $size[0],
            'hoehe' => $size[1],
            'zoll' => $size[2]
        );
    }else {
        $query = $this->db->query("
            SELECT mo.front, mo.back
            FROM " . DB_PREFIX . "model mo
            WHERE mo.id != 0
            $where
        ")->rows;
                 var_dump($query); 
             (result this code is comment only for show you
                array (size=2)
                'front' => string '110|70|17' (length=9)
                'back' => string '130|70|17' (length=9)
                 )
         $size = explode("|", $query[0]);
               there is litle problem i need expolde front and back with |
        $data2 = [];
        $data2['atts'] = [
            'breite' => $size[0],
            'hoehe' => $size[1],
            'zoll' => $size[2]
        ];
         (resulte write only for you
              var_dump($data2);
              array (size=1)
          'atts' => 
             array (size=3)
                'breite' => null
                'hoehe' => null
                'zoll' => null
    }
          )

看看我需要得到的专栏: https ://imgur.com/YK9wNRy

这只是拥有超过 150 行代码的功能的一部分。我认为问题就在这里,这就是为什么我告诉你我不会把所有的东西都写得太大而你不会明白。如果你有问题在这里。如果你想要我向你展示的所有功能。前面是 react.js,但现在这并不重要。谢谢

标签: php

解决方案


推荐阅读