zencart的modules下数据库操作templates排版和common首页引用
把这个学会,zencart的数据库操作,以及各种函数的调用基本会了
这个东西非常有用,你需要认真看一下,不要闲代码多。
如何在数据库中调出自己想要的产品,让它显示在首页。
据我本人不科学的理解,在includes/modules/里面见一个 模块文件,该文件是功能文件,也就是含有sql语句,以及执行sql语句的常用函数,这个是“功能文件”
我在这取名叫做 show_products.php
<?php
$show_product = 'SELECT p.products_id,p.products_model,p.products_price, p.products_image, ps.specials_new_products_price,pd.products_name,pd.products_description,cd.categories_description,cd.categories_id FROM products p
LEFT JOIN specials ps ON ps.products_id = p.products_id
LEFT JOIN products_description pd ON pd.products_id = p.products_id
LEFT JOIN products_to_categories pc ON pc.products_id = p.products_id
LEFT JOIN categories_description cd ON cd.categories_id = pc.categories_id order by rand()';
$show_product_handle = $db->Execute($show_product,18);
while (!$show_product_handle->EOF)
{
$show_product_content[] = array(
'id'=>$show_product_handle->fields['products_id'],
'product_name'=>$show_product_handle->fields['products_name'],
'products_description'=>$show_product_handle->fields['products_description'],
'product_module'=>$show_product_handle->fields['products_model'],
'product_price'=>$currencies->display_price(zen_get_products_base_price($show_product_handle->fields['products_id'])),
'special_price'=>$currencies->display_price(zen_get_products_special_price($show_product_handle->fields['products_id'])),
'description'=>$show_product_handle->fields['categories_description'],
'product_image'=>zen_image(DIR_WS_IMAGES . $show_product_handle->fields['products_image'], $show_product_handle->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT),
'product_url'=>zen_href_link(FILENAME_PRODUCT_INFO,'cPath='. $show_product_handle->fields['categories_id'] . '&products_id='.$show_product_handle->fields['products_id'])
);
$show_product_handle->MoveNext();
//print_r($show_product_handle);
}
//print_r($show_product_content);
?>
东西取出来了,得要按照我们需要的格式排列啊,就需要模板文件,在includes/templates/template_default/templates/建一个tpl_show_products.php的模板文件
<?php
include(DIR_WS_MODULES . zen_get_module_directory('show_product.php'));
if(is_array($show_product_content) && !empty($show_product_content))
{
$outPutHtml .= '<div id="product">';
$i=0;
$j=0;
foreach ($show_product_content as $key => $value)
{
$str=$value['products_description'];
$val=substr($str,0,170)."...";
$outPutHtml .= '<div id="Box'. $value['id'] .'">';
$outPutHtml .= '<div id="BoxT'. $value['id'] .'">';
$outPutHtml .= '<h2><a href="' . $value['product_url'] . '">' . $value['product_name'] . '</a></h2>';
$outPutHtml .= '</div>';
$outPutHtml .= '<div class="desc"><a href="' . $value['product_url'] . '" class="kuang" alt=" '. $value['product_name'] .' "></a></div>';
$outPutHtml .= '<div id="BoxD' . $value['id'] . '">';
$outPutHtml .= '<h3><span>RRP: ' . $value['product_price'] . '</span> - OUR PRICE: ' . $value['special_price'] . '</h3>';
$outPutHtml .= $val;
$outPutHtml .= '</div>';
$outPutHtml .= '<div id="BoxB' . $value['id'] . '">';
$outPutHtml .= '<a href="' . $value['product_url'] . '"><img src="includes/templates/2/images2/'. $value['id'] .'.gif"></a>';
$outPutHtml .= '</div>';
$outPutHtml .= '</div>';
// print_r($value);
}
$outPutHtml .= '</div>';
}
echo $outPutHtml;
//print_r($show_product_content);
?>
<!--
<div id="p_1">
<div id="p_li">
<h2><a href="ghd-red-lust-styler-p-252.html">GHD Pink Limited Edition</a></h2>
</div>
<a href="ghd-pink-limited-edition-p-255.html" class="kuang" alt="GHD Red Lust Styler"></a>
<div id="text">
<h3><span>RRP: $299.00 AUD</span> - OUR PRICE: $145.99 AUD</h3>
2010 ghd pink limited edition-Rediscover your passion for pink with the new ghd Pink limited edition.Each pink patterned ghd IV styler comes with a gorgeous raffia bag & mirror. </div>
</div>
<div id="an">
<a href="ghd-pink-limited-edition-p-255.html"><img src="includes/templates/2/images2/p_an_4.jpg"></a>
</div>
-->
最后是引用这一块,比如我想在首页的一个DIV里显示这些内容
<div class="products">
<?php
//display product module
require($template->get_template_dir('tpl_module_show_product.php', DIR_WS_TEMPLATE, $current_page_base, 'templates').'/tpl_module_show_product.php');
?>
</div>
zencart的modules下数据库操作templates排版和common首页引用的更多相关文章
- Android下数据库操作——增删改查
Android下数据库第一种方式增删改查 1.创建一个帮助类的对象,调用getReadableDatabase方法,返回一个SqliteDatebase对象 2.使用SqliteDat ...
- Oracle Linux下数据库操作的相关问题
1.su - oracle 切换到oracle用户 lsnrctl status 查看数据库监听状态 lsnrctl start 打开数据库监听 2.Connected to an idle inst ...
- c#数据库访问服务(综合数据库操作)
前面给大家说封装了常用的数据库,并且整理了使用.最近我再次把项目整合了.做成比较完善的服务. 还是重复的说下数据库操作封装. berkeley db数据库,Redis数据库,sqlite数据库. 每个 ...
- 如何在高并发环境下设计出无锁的数据库操作(Java版本)
一个在线2k的游戏,每秒钟并发都吓死人.传统的hibernate直接插库基本上是不可行的.我就一步步推导出一个无锁的数据库操作. 1. 并发中如何无锁. 一个很简单的思路,把并发转化成为单线程.Jav ...
- mysql在cmd命令下执行数据库操作
windows+r 运行cmd命令,执行以下操作! 当mysql 数据库文件相对于来说比较大的时候,这个时候你可能在正常环境下的mysql中是导入不进去的,因为mysql数据库本身就有默认的导入文件大 ...
- Django 2.0 学习(16):Django ORM 数据库操作(下)
Django ORM数据库操作(下) 一.增加表记录 对于表单有两种方式: # 方式一:实例化对象就是一条表记录france_obj = models.Student(name="海地&qu ...
- Python3.x:pyodbc连接Sybase数据库操作(Windows系统下DNS模式)
Python3.x:pyodbc连接Sybase数据库操作(Windows系统下DNS模式) 一.安装模块pyodbc pip install pyodbc 二.配置odbc数据源 (1).windo ...
- 数据库操作API 或万能的双下划线
数据库操作API: 类型 描述 exact 精确匹配: polls.get_object(id__exact=14). iexact 忽略大小写的精确匹配: polls.objects.filter( ...
- Django 模型(数据库)-cmd下的操作
Django 模型是与数据库相关的,与数据库相关的代码一般写在 models.py 中,Django 支持 sqlite3, MySQL, PostgreSQL等数据库,只需要在settings.py ...
随机推荐
- android网络编程之HttpUrlConnection的讲解--POST请求
1.服务器后台使用Servlet开发,这里不再介绍. 2.网络开发不要忘记在配置文件中添加访问网络的权限 <uses-permission android:name="android. ...
- 使用 HTML5 input 类型提升移动端输入体验(键盘)
在最近的项目中,策划老是要求我们弹出各种类型的键盘,特别是在iOS下,例如输入帐号的时候,不应该支持输入中文,该输入纯数字的时候就应该谈数字键盘等.个人觉得这些都是我们平时开发很少意识到的,虽然有些刁 ...
- C++ 中Hello World的一种写法
/*C++ Hello World**/#include <stdio.h>#include <iostream>int main(){ printf("Hel ...
- 使用anyremote进行远程鼠标控制
源代码安装 http://anyremote.sourceforge.net/pre.html 安装 -xtest apt-get install libxtst-dev 安装 glib sudo ...
- spice-vdagent
The spice-vdagent should be running in the guest. Have you installed the spice guest tools in your w ...
- weak和assign区别
weak比assign多了一个功能,当对象消失后自动把指针变成nil haofanazenmeban[4002:406590] controller:<SecondViewController: ...
- 初识Ubuntu
刚刚装好bantu 16.10就遇到了好多问题,记录一下 一.卸载一些用不到的软件. 1.su认证失败 sudo passwd //输入命令,然后修改密码即可 2.卸载libreoffice sudo ...
- php薪资
2千的php程序员就是可以用cms,做一个小企业的门户网站. 3千的php程序员,可以自己写代码开发php软件,但是这样程序员写的代码非常混乱,通常只能写数千行代码的小软件,并且痛苦的完工. 4K的p ...
- html 7.29
4.请判断以下说法是否正确:HTML 会被 XHTML 取代. 您的回答:错误 正确答案:正确 9.请判断以下说法是否正确:DOCTYPE 没有关闭标签. 您的回答:错误 正确答案:正确 13.下列哪 ...
- ACM暑期训练总结
ACM暑期集训总结报告 不知不觉,ACM暑期集训已经过去了一个月了(其实我还差几天才够一个月,因为最后几天要回家办助学贷款,所以没坚持到最后,当了个逃兵.....[汗])也到了结束的时候.在这一个月中 ...