zencart的数据库操作,以及各种函数的调用
2012-06-01 10:49
417 查看
把这个学会,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>
http://blog.sina.com.cn/s/blog_900af2a80100wcgr.html
这个东西非常有用,你需要认真看一下,不要闲代码多。
如何在数据库中调出自己想要的产品,让它显示在首页。
据我本人不科学的理解,在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>
http://blog.sina.com.cn/s/blog_900af2a80100wcgr.html
相关文章推荐
- 把这个学会,zencart的数据库操作,以及各种函数的调用基本会了
- Mysql 数据库 基本操作以及调用(一)
- Java-数据库操作 过程proc、函数func调用
- C#中对数据库的基本操作(增删改以及调用存储过程)
- Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库 自定义日志记录功能,按日记录,很方便 C#常量和字段以及各种方法的语法总结 类型,对象,线程栈,托管堆在运行时的关系,以及clr如何调用静态方法,实例方法,和虚方法 asp.net webapi 自定义身份验证
- C#中对数据库的基本操作(增删改以及调用存储过程)
- 数据库中的各种约束以及对约束的操作
- 动态函数调用实现下列操作,输入2个数以及操作符计算结果。 @ 求最大公约数 $求最小公倍数 - 求差 + 求和 等等
- 用 JavaScript 写 ASP,似乎很爽啊,自己封装了一个 操作数据库 分页 以及 文件操作的函数
- java中用事物控制语言调用数据库中的数据,以及调用存储过程或函数
- 关于动态存储分配函数的调用,在已经过排序的数组中查找及删除内容的操作,余数的分析,删除字符数组中的空格,对链表的逆置,在源字符串中查找子字符串的个数,函数指针以及函数的调用,循环赋值带来的问题以及插入
- Java连接各种数据库以及调用存储过程
- Oracle数据库的概念(权限、角色)以及各种操作(创建表空间、创建表、查询、更新、删除、插入)和常用函数
- sqlite 数据库 支持的数据类型 以及常用的函数
- HEVC/H.265整个程序调用流程分析以及函数复杂度分析 .
- 通过函数调用对字符串数组进行各种排序
- Java中调用数据库的存储过程存储函数和包体
- Spring中c3p0连接池的配置 及JdbcTemplate的使用 通过XML配置文件注入各种需要对象的操作 来完成数据库添加Add()方法
- NSInvocaion用来替代performSelector传多个参数时,以及根据函数签名来动态调用时
- 工作笔记(五):常用jquery函数以及操作,持续更新..