SQL这句写成这样吗?$sql="SELECT attr_value FROM ecs_goods_attr WHERE attr_id = 1 AND goods_id = getOne($goods[$idx]['id'] )";这样写报错啊……我想在SQL里goods_id这个是获取当前的goods_id,就像在模板里用{$goods.id}一样SQL那个地方换成什么呢?goods_id = getOne($goods[$idx]['id'] ) 这样写报错啊
SQL这句写成这样吗?$sql="SELECT attr_value FROM ecs_goods_attr WHERE attr_id = 1 AND goods_id = getOne($goods[$idx]['id'] )"; 是这样: $sql="SELECT attr_value FROM ecs_goods_attr WHERE attr_id = 1 AND goods_id = '.$goods[$idx]['id']); $res = getOne($sql);//此时$res是goods_id = $goods[$idx]['id']的商品的attr_value
$sql="SELECT attr_value FROM ecs_goods_attr WHERE attr_id = 1 AND goods_id = ".$goods[$idx]['id']);
$sql="SELECT attr_value FROM ecs_goods_attr WHERE attr_id = 1 AND goods_id = ".$goods[$idx]['id']);这句在编辑器里提示有语法错误运行报错Parse error: syntax error, unexpected ')' in \includes\lib_goods.php on line 329嗯,掉了一个(,我改成这样 $sql="SELECT attr_value FROM ecs_goods_attr WHERE attr_id = 1 AND goods_id = ".($goods[$idx]['id']);成功了,太感谢了,太感谢了,太感谢了
普通的PHP就行,感觉用了smarty好像还更麻烦
普通的php查询SQL然后输出就行了
实在没有PHP知识。只会前端和基础SQL,真是惭愧啊,求各位大哥指教
function insert_execSQL($param){
//echo '<pre>';print_r($param);exit;//输出模板中insert传过来的所有参数,你可以进行相当的处理
return $param['a'];
}在smarty模板中类似如下:
{insert name="execSQL" a=1}//“{}”是边界符,a=1传递给php中的insert_execSQL的另一个参数,最终输出1,以此类推在php中的insert_execSQL中你向执行什么不行呢,smarty中你想传过去什么参数传递不过去呢
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.et_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, g.goods_img, RAND() AS rnd " .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ";
$type_merge = array_merge($type_array['new'], $type_array['best'], $type_array['hot']);
$type_merge = array_unique($type_merge);
$sql .= ' WHERE g.goods_id ' . db_create_in($type_merge);
$sql .= ' ORDER BY g.sort_order, g.last_update DESC'; $result = $GLOBALS['db']->getAll($sql);
foreach ($result AS $idx => $row)
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
}
else
{
$goods[$idx]['promote_price'] = '';
} $goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : '';
$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]['et_price'] = price_format($row['et_price']);
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);我想在$goods[$idx]['id'] = $row['goods_id'];加入$goods[$idx]['pro_1'],想让$goods[$idx]['pro_1']为查询SQL的语句的运行结果
SQL如下,该怎么写这句呢?SELECT attr_value FROM ecs_goods_attr WHERE attr_id = 1 AND goods_id = 32
$goods[$idx]['id'] = ??????????
$goods[$idx]['pro_1'] = $GLOBALS['db']->getOne($sql);这样写?出不来啊?
$goods[$idx]['pro_1'] = $GLOBALS['db']->getOne($sql);这样写可以了。但是还需要把SQL里的最后一个条件goods_id = 32,换成goods_id = $goods[$idx]['id'] = $row['goods_id']; goods_id为当前的goods_id,怎么换呢?
是这样:
$sql="SELECT attr_value FROM ecs_goods_attr WHERE attr_id = 1 AND goods_id = '.$goods[$idx]['id']);
$res = getOne($sql);//此时$res是goods_id = $goods[$idx]['id']的商品的attr_value
$sql="SELECT attr_value FROM ecs_goods_attr WHERE attr_id = 1 AND goods_id = ".($goods[$idx]['id']);成功了,太感谢了,太感谢了,太感谢了