您现在的位置是:首页 > cms教程 > Ecshop商城教程Ecshop商城教程

ecshop错误提示Warning: Invalid argument supplied for foreach

亦玉2025-01-21Ecshop商城教程已有人查阅

导读1.php下foreach()错误提示Warning: Invalid argument supplied for foreach()
错误提示:Warning: Invalid argument supplied for foreach() in E:wamp myshopcart.php on l

1.php下foreach()错误提示Warning: Invalid argument supplied for foreach()
错误提示:Warning: Invalid argument supplied for foreach() in E:wamp myshopcart.php on line 95
二、解决方案:
错误提示 Warning:Invalid argument supplied for foreach() 的中文意思是说foreach需要是一个数组而给它的是一个无效的参数,就是在循环前面加上判断,直接使用is_array判断给的值是不是为数组,代码如下:
if(is_array($items) && !emptyempty($items)){
foreach( )
}
或者强制转换数据类型,代码如下:
foreach((array)$v as $k1 => $v1) {
$edu[$k1][$k] = my_h($v1);// v1是最终要入库的数据,进行转义处理
}
2.后台添加导航的错误
3.首页显示分类产品列表在lib_goods.php里加个这个
/**
* 首页获取指定分类产品
*
* @access public
* @param string
* @param array
* @return array
*/
function get_cat_id_goods_list($cat_id = '', $num = '') {
$sql = 'Select g.goods_id, g.cat_id,c.parent_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, " .
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, " .
"g.is_best, g.is_new, g.is_hot, g.is_promote " .
'FROM ' . $GLOBALS ['ecs']->table ( 'goods' ) . ' AS g ' .
'LEFT JOIN ' . $GLOBALS ['ecs']->table ( 'category' ) . ' AS c ON c.cat_id = g.cat_id ' .
"LEFT JOIN " . $GLOBALS ['ecs']->table ( 'member_price' ) . " AS mp " .
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
"Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " .
$sql .= " AND (c.parent_id =" . $cat_id . " OR g.cat_id = " . $cat_id . " OR g.cat_id " . db_create_in ( array_unique ( array_merge ( array (
$cat_id
), array_keys ( cat_list ( $cat_id, 0, false ) ) ) ) ) . ")";
$sql .= " LIMIT $num";
$res = $GLOBALS ['db']->getAll ( $sql );
$goods = array ();
foreach ( $res as $idx => $row ) {
$goods [$idx] ['id'] = $row ['article_id'];
$goods [$idx] ['id'] = $row ['goods_id'];
$goods [$idx] ['name'] = $row ['goods_name'];
$goods [$idx] ['brief'] = $row ['goods_brief'];
$goods [$idx] ['brand_name'] = $row ['brand_name'];
$goods [$idx] ['goods_style_name'] = add_style ( $row ['goods_name'], $row ['goods_name_style'] );
$goods [$idx] ['short_name'] = $GLOBALS ['_CFG'] ['goods_name_length'] > 0 ? sub_str ( $row ['goods_name'], $GLOBALS ['_CFG'] ['goods_name_length'] ) : $row ['goods_name'];
$goods [$idx] ['short_style_name'] = add_style ( $goods [$idx] ['short_name'], $row ['goods_name_style'] );
$goods [$idx] ['market_price'] = price_format ( $row ['market_price'] );
$goods [$idx] ['shop_price'] = price_format ( $row ['shop_price'] );
$goods [$idx] ['thumb'] = empty ( $row ['goods_thumb'] ) ? $GLOBALS ['_CFG'] ['no_picture'] : $row ['goods_thumb'];
$goods [$idx] ['goods_img'] = empty ( $row ['goods_img'] ) ? $GLOBALS ['_CFG'] ['no_picture'] : $row ['goods_img'];
$goods [$idx] ['url'] = build_uri ( 'goods', array (
'gid' => $row ['goods_id']
), $row ['goods_name'] );
}
return $goods;
}
然后是index.php输出
$smarty->assign('cat_id_goods_list_19', get_cat_id_goods_list(19,10));//进口水果额
之后前台一遍历
4.首页显示文章上传的file_url字段 来当图片用在对应的php方法里加个 file_url字段即可
5.后台添加导航碰到这个错误 咋整
解决下:上面代码可以输出值,但是报错Warning: Illegal string offset 'cat_name' in ,原因是$catlist数组里面有空数组,空数组里没有cat_name这个字段。最终解决办法是在 foreach 下面加个判断 if(is_array($val)),这样就搞定了。
6.登陆的时候 登陆没通过 有错误
构造函数放到方法上面就好了
7.Ecshop 如何在全站都调用购物车信息 比如买了几件 一共多少钱
8.文章列表页如何显示网页描述字段
9.登陆注册页面显示产品分类列表根目录的user.php 里大概79行 加一句这个
$smarty->assign('categories', get_categories_tree()); // 分类树
10. Strict Standards: mktime(): You should be using the time() function instead in E:\web\shopex\admin\shop_config.php on line 32
这个错误提示的意思:mktime()方法不带参数被调用时,会被抛出一个报错提示。
找到文件第32行:
$auth = mktime();
将mktime()替换成time()方法,代码为:
$auth = time();
11. Strict standards: Redefining already defined constructor for class cls_sql_dump in
调换一下两个函数的前后位置即可。
以 includes/modules/payment/alipay.php 为例:
将下面这两个函数的位置互换一下就OK了,__c**truct()在前,alipay()在后
function alipay() {
}
function __c**truct()
{
$this->alipay();
}
12. Strict standards: Non-static method cls_sql_dump::get_random_name() should not be called statically
13.上传的图片不清楚怎么办
按照路径直接找到根目录下thems/default/goods.dwt这个文件 直接修改模板文件即可
找到:
<div class=”good_img”>
<a href=”javascript:;” onclick=”window.open(‘gallery.php?id={$goods.goods_id}’); return false;” >
<img src=”{$goods.goods_img}” alt=”{$goods.goods_name|escape:html}” id=”goodsimg” style=”width:340px;” />
</a>
</div>
修改为:
<div class=”good_img”>
<a href=”javascript:;” onclick=”window.open(‘gallery.php?id={$goods.goods_id}’); return false;” >
<img src=”{$goods.original_img}” alt=”{$goods.goods_name|escape:html}” id=”goodsimg” style=”width:340px;” />
</a>
</div>

本文标签:

很赞哦! ()

相关源码

  • 响应式HTML5家居建材办公家具桌椅pbootcms模板为家居建材、办公家具企业打造的响应式网站模板,同时支持多行业快速适配通过替换文字图片即可转型为其他行业官网,大幅降低开发成本。查看源码
  • (自适应响应式)工业机床工程农业机械设备网站源码下载框架适用于工程机械、机床设备等工业领域。通过模块调整可快速转型为农业机械、物流设备展示系统。预留7种工业产品展示模板。查看源码
  • (PC+WAP)pbootcms模板黑色门窗定制五金建材网站下载为门窗定制与五金建材企业设计的网站解决方案,采用PbootCMS开发,兼具专业展示与营销功能。黑色系设计突显工业质感,响应式布局确保在手机、平板等设备上的浏览体验。通过简单的内容替换,也可适用于建材贸易、家具定制等相关行业。查看源码
  • (自适应)帝国CMS7.5模板淘宝客导购博客文章源码本模板基于帝国CMS7.5内核深度开发,为电商导购类网站设计。采用响应式布局技术,确保在手机、平板及电脑端均能获得优质浏览体验。模板内置商品推荐模块与优惠信息展示区,可快速搭建专业导购平台。查看源码
  • (自适应响应式)高端珠宝首饰奢侈品pbootcms模板下载本模板为珠宝首饰及奢侈品行业打造,采用PbootCMS内核开发,具备卓越的视觉表现力与商业转化能力。自适应设计确保在手机端呈现产品细节,后台数据实时同步,助您高效展示钻石查看源码
  • WordPress主题模板主题巴巴/博客X主题源码免费下载博客X主题专注于内容创作领域,为博客、资讯类网站提供专业的内容展示解决方案。该模板采用精心设计的布局结构,能够有效提升内容的可读性和用户停留时间。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐