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);
magento数据查询的更多相关文章
- Django models .all .values .values_list 几种数据查询结果的对比
Django models .all .values .values_list 几种数据查询结果的对比
- MVC实用架构设计(三)——EF-Code First(4):数据查询
前言 首先对大家表示抱歉,这个系列已经将近一个月没有更新了,相信大家等本篇更新都等得快失望了.实在没办法,由于本人水平有限,写篇博客基本上要大半天的时间,最近实在是抽不出这么长段的空闲时间来写.另外也 ...
- 关系数据库SQL之高级数据查询:去重复、组合查询、连接查询、虚拟表
前言 接上一篇关系数据库SQL之基本数据查询:子查询.分组查询.模糊查询,主要是关系型数据库基本数据查询.包括子查询.分组查询.聚合函数查询.模糊查询,本文是介绍一下关系型数据库几种高级数据查询SQL ...
- SharePoint服务器端对象模型 之 使用CAML进展数据查询
SharePoint服务器端对象模型 之 使用CAML进行数据查询 一.概述 在SharePoint的开发应用中,查询是非常常用的一种手段,根据某些筛选.排序条件,获得某个列表或者某一些列表中相应的列 ...
- .NET应用架构设计—面向查询服务的参数化查询设计(分解业务点,单独配置各自的数据查询契约)
阅读目录: 1.背景介绍 2.对业务功能点进行逻辑划分(如:A.B.C分别三个业务点) 2.1.配置映射关系,对业务点配置查询契约(构造VS插件方便生成查询契约) 2.2.将配置好的映射策略文件放在调 ...
- Yii2 数据查询
转载来自: http://www.yiichina.com/tutorial/95 数据查询 User::find()->all(); 此方法返回所有数据: User::findOne($id) ...
- 6、SQL Server 数据查询
一.使用SELECT检索数据 数据查询是SQL语言的中心内容,SELECT 语句的作用是让数据库服务器根据客户要求检索出所需要的信息资料,并按照规定的格式进行整理,返回给客户端. SELECT 语句的 ...
- SQL Server 的表数据简单操作(表数据查询)
--表数据查询----数据的基本查询-- --数据简单的查询--select * | 字段名[,字段名2, ...] from 数据表名 [where 条件表达式] 例: use 商品管理数据库 go ...
- asp.net mvc 数据查询赋值到文本框中
大家做了很多文本框查询并且赋值回来 1.先是把数据对象查询结果后台,然后把对象赋值给对象在赋值回来前台页面 2.使用@html helerper 数据查询,使用 ViewContext.RouteDa ...
随机推荐
- CodeForces 157C Message
$dp$. $dp[i][j]$表示$s[i]$到$s[j]$和$t[lent-1+i-j]$到$t[lent-1]$有$dp[i][j]$位相同,然后枚举一遍$dp[i][j]$就可以算出答案了. ...
- C#中int32 的有效值范围
C#中int32 的有效值范围是[Int32.MinValue, Int32.MaxValue]中的整数,或者说是从 -2^16 到 2^16-1 之间的整数
- wpf 界面线程 添加项
foreach (var r in sec.Records) { listView.Dispatcher.Invoke((new Action(delegate() { listView.Items. ...
- 关于泛型中<T extends comparable>的理解
public static <T extends Comparable> T min(List<T> t); 对于上面定义的泛型方法min中,Comparable指的是一个接口 ...
- Qt 打开指定的文件
最近项目用到使用本地的office打开指定的文件,记录一下代码: QString fileName = QFileDialog::getOpenFileName(this, tr("Open ...
- Linq to Sql 左连接查询
var query = from t0 in context.ExpressSendMaster join t1 in context.Supplier on t0.SupplierCode equa ...
- Java错误提示is not an enclosing class
今天脑袋晕乎乎的,犯了个低级错误,好半天才反应过来 一直提示:is not an enclosing class 我居然把 RegisterActivity.class 写成了 RegisterAct ...
- xaml中的依赖属性
wpf使用依赖属性完成数据绑定.动画.属性变更通知.样式化等.对于数据绑定.绑定到.NET属性源上的UI元素的属性必须是依赖属性 .net的一般属性定义如下 private int val; ...
- C#+ArcEngine中com对象的释放问题
1.问题描述 最近在写C#下AE的开发,在循环获取数据并修改时碰到了两个问题"超出系统资源"和"超出打开游标最大数":在网上看了一些资料,发现都是说在循环中没有 ...
- Zsh安装
Zsh 使用 Homebrew 完成 zsh 和 zsh completions 的安装 brew install zsh zsh-completions 安装 oh-my-zsh 让 zsh 获得拓 ...