我需要查询 " . $GLOBALS['ecs']->table('user_card') . " 表里的 card_no字段里是否有 $model内容,指定修改条数后执行修改。
if ($_REQUEST['act'] == 'model'){
$model_id = $_POST['model']; //获取提交过来的产品型号
$number = $_POST['number']; //获取需要修改数量
$startymd = $_POST['startymd']; //获取需要写入的日期
/* //这段代码应该写错的了,我都不知道怎么写了,怎么循环。
$card_null = mysql_query ( "SELECT id FROM " . $GLOBALS['ecs']->table('user_card') . " WHERE `enable` = '0' AND `card_no` LIKE '%$model_id%' order by id ASC limit " . $number);
foreach (mysql_fetch_array($card_null) as $result) {
if($result['id']) {
$db -> query("UPDATE ".$GLOBALS['ecs']->table('user_card')." SET `date`=".$startymd.",`enable`=1 WHERE `id`= ".$result['id']);
} else {
echo '积分卡不够用,请导入后继续!';
}
}
*/
}
回复讨论(解决方案)
while($result = mysql_fetch_array($card_null)) {if($result['id']) {$db -> query("UPDATE ".$GLOBALS['ecs']->table('user_card')." SET `date`=".$startymd.",`enable`=1 WHERE `id`= ".$result['id']);} else {echo '积分卡不够用,请导入后继续!';}}
可以实现批量修改了,
$card_null = mysql_query( "SELECT id FROM " . $GLOBALS['ecs']->table('user_card') . " WHERE `enable` = '0' AND `card_no` LIKE '%$model_id%' order by id ASC limit " . $number);
while($result = mysql_fetch_array($card_null)) {
if($result['id']) {
$db -> query("UPDATE ".$GLOBALS['ecs']->table('user_card')." SET `enable_time`='$time',`date`='$startymd',`enable`=1 WHERE `id`= ".$result['id']);
echo '操作成功';
} else {
echo '积分卡不够用,请导入后继续!';exit;
}
}
怎样改成当$card_null没有查询到数据后输出 echo "积分卡不够用"
本文原创发布php中文网,转载请注明出处,感谢您的尊重!