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 ...
随机推荐
- CSS3的radial-gradient(径向渐变)
所谓径向渐变,如图下,类似光晕 语法: radial-gradient( [ [渐变大小]? [ at 渐变圆心坐标]? ,]? 颜色[ 开始位置] [,颜色[ 开始位置]]+); ...
- Matlab最新的官方文档中文翻译
文章翻译的是Matlab最新的官方文档R2016b,可能后续如果我还有时间会继续翻译,希望能够帮到大家,翻译的不好请大家不要吐槽. Matlab官方文档地址:http://cn.mathworks.c ...
- ubuntu 下 编译ffmpeg 3.1.1
1,下载ggmpeg源码:http://ffmpeg.org/download.html 2.下载ndk ,百度 3.配置环境 3.1 编译FFMPEG时,出现了 ffmpeg yasm not fo ...
- OSI模型第二层数据链路层-STP协议
1.stp协议的由来. 在二层网络中,交换机起到了很重要的作用,如果有一台交换机出现故障会影响网络的使用,为了避免存在单点故障,在实际的二层链路中会采用链路冗余,也就是采用交换设备之间多条联络连接,即 ...
- Zeppelin 用jdbc连接hive报错
日志: Could not establish connection to jdbc:hive2://192.168.0.51:10000: Required field 'serverProtoco ...
- LeetCode 213. House Robber II
Note: This is an extension of House Robber. After robbing those houses on that street, the thief has ...
- ele.me在IOS浏览器端启动APP的技巧分析
ele.me在IOS浏览器端启动APP的技巧分析 巧妙利用后台重定向,在schemes启动时提示用户打开,启动不了APP时能够及时跳转至下载页面. 避免报错页面的出现以及用户还没来的及选择就跳转到下载 ...
- CodeForces 709C Letters Cyclic Shift
贪心. 肯定是两个$a$之间的那些字符都$-1$,没有$a$就全部$-1$.如果输入的串全是$a$,那么把最后一个$a$改成$z$. #pragma comment(linker, "/ST ...
- Ubuntu火狐、Chromium等浏览器安装flash插件
1.打开系统设置->软件和更新->其他软件,勾选Canonical合作伙伴,输入密码,重新载入更新 2.打开终端,按装插件 sudo apt install adobe-flashplug ...
- 仿qq的条目抽屉动画效果_ViewDragHelper
GitHub地址: https://github.com/OOOOOldZhu/DrawerItemView import android.content.Context; import androi ...