• magento数据查询


    一.查询出所有的数据:

    1.以mysql查询语句在magento里执行,以此来查询你所需要的语句!

    $read = Mage::getSingleton('core/resource')->getConnection('core_read');  
     $sql = "select name from user_data where id = 1 limit 1";  
      $row = $read->fetchAll($sql );

    2.以damp文件来在magento里查询你的数据

    <?php
        header("Content-type:text/html;charset=utf-8");
        require_once '../../app/Mage.php';
        Mage::app ('admin');
       $read = Mage::getSingleton('core/resource')->getConnection('core_read');

        //下面是你所需要查询的表(设置获取表名)
       $table = Mage::getSingleton('core/resource')->getTableName('dipper_tdata/table');  
       

        //根据你的要求查询数据 
        $select = $read->select()->from($table)->where("sup_id = 10000 and postage_type = 0");  

        //执行查找出所有的数据记录(這里获取的数据不是对象而是一个数组)
        $row = $read->fetchAll($select);

    3.第三种获取数据的方法!

    <?php
        header("Content-type:text/html;charset=utf-8");
        require_once '../../app/Mage.php';
        Mage::app ('admin');
         

        //提出所有的数据:(取出整张表的数据)
        $inventoryTicket = Mage::getModel('fulfillment/inventory_ticket')->getCollection();
        foreach($inventoryTicket as $item){
        $data=$item->getData();
        echo $data;
        echo $data['entity_id'];
        }

     4.非EAV表的查询

    $accountCol = Mage::getModel('bf170card/account')->getCollection();
     $accountCol ->addFieldToFilter('card_number', array('like' => '17076%'));
     $accountCol->setCurPage(2); // 第几页
     $accountCol->setPageSize(3);//每页几个
      foreach($accountCol as $account){
          var_dump( $account->getData());
     $accountCol->clear();
     $accountCol->addFieldToFilter('card_number' , '17076597077' );
     foreach($accountCol as $account){
          var_dump( $account->getData());
          echo '<br/>';
          }

     5.EAV表的查询
     $productCol = Mage::getModel('catalog/product' )->getCollection();
     

    // collection缺省只包含主表里的数据(即EAV中的entity表里面的数据),以及一些个别的数据点
      // 如果需要添加属性,可使用addAttributeToSelect
     $productCol->addAttributeToSelect(array ('name' , 'description' ));
     $productCol->addAttributeToFilter('url_key' , 'crab' );//起到过滤的作用
     $productCol->addAttributeToSort ( 'entity_id', 'desc' )
                ->setPageSize(5);

    $productids = $productCol->getAllIds();//这个是获取所有的id.
     $productCol->setCurPage(2 );// 第几页
     $productCol->setPageSize(3 );//每页几个
     foreach($productCol as $product){
     var_dump( $product->getData());
     echo '<br/>';
    // 如果用load($id)方法,会拿到所有数据,但是效率会低
     $productWithFullData = Mage::getModel('catalog/product' )->load($product->getId());
     var_dump( $productWithFullData->getData());
      echo '<br/>';
       load($value,$key)的使用方法:
        $relationship = Mage::getModel('customer/customer')->load($customer->getId(),'customer_id');
    这上面的意思是获取customer_id是$customer->getId()的数据.
    $customer = Mage::getModel('hpusenetwork/relationship')->loadByTelephone($customerTelephone);

    6.链表查询

      $recordCol = Mage::getModel('sales/order_shipment_track')->getCollection();
                $orderAddressTableName = Mage::getSingleton('core/resource')->getTableName('sales/order');
                $recordCol->getSelect()->joinLeft(
                        array('order' => $orderAddressTableName),
                        "main_table.order_id = order.entity_id",
                        array(
                            'increment_id'=>'order.increment_id'
                        )
                )->where('customer_id=?',$customer);

  • 相关阅读:
    P3834 【模板】可持久化线段树 (静态主席树)
    P3834 【模板】可持久化线段树 (静态主席树)
    2019 南昌网络赛 I. Max answer
    Linux从入门到精通——系统的进程
    Linux从入门到精通——文件权限
    Linux从入门到精通——命令行使用技巧
    Linux从入门到精通——Linux系统的文件及其管理
    Linux从入门到精通——vim及管理输入输出
    Linux从入门到精通——用户管理
    thiny mission 2021 10 15
  • 原文地址:https://www.cnblogs.com/sqsnbrdcwlcfzj/p/6220876.html
Copyright © 2020-2023  润新知