数组默认值插入不正确插入数据?
array defult value insert not proper insert data?
我正在使用 CodeIgniter 插入数组值问题第一个数组值插入正常但多个值插入不正确所以请分享宝贵的想法先生。我在这里分享所有问题代码...
CodeIgniter 模型
public function savemedicine()
{
$db2 = $this->load->database('dpr',TRUE);
$medicine_typer = array("CAB", "TAB", "CAB","CAB");
$pricer = array("202", "100", "97","92");
$quantityr = array("2","2","1","3");
foreach ($item_namer as $key => $value){
//print_r($medicine_typer[$key]);//output CABA
//print_r($quantityr[$key]);//output 2
//print_r($pricer[$key]);//output 2020
$medicine_typer =$medicine_typer[$key];
$quantityr =$quantityr[$key];
$pricer =$pricer[$key];
$db2->query('INSERT INTO dpr_medicine_return(medicine_type,quantity,price)
VALUES ("'.$medicine_typer.'","'.$quantityr.'","'.$pricer.'")');
$i++;
}
}
you are revaluing variable in the loop so when the loop run for 2 time the
time it didn't find those array variable but now they are not array
use this code
$medicine_typer2 =$medicine_typer[$key];
$quantityr2 =$quantityr[$key];
$pricer2 =$pricer[$key];
$itemidr2 =$item_idr[$key];
now use these variable in your query
我正在使用 CodeIgniter 插入数组值问题第一个数组值插入正常但多个值插入不正确所以请分享宝贵的想法先生。我在这里分享所有问题代码...
CodeIgniter 模型
public function savemedicine()
{
$db2 = $this->load->database('dpr',TRUE);
$medicine_typer = array("CAB", "TAB", "CAB","CAB");
$pricer = array("202", "100", "97","92");
$quantityr = array("2","2","1","3");
foreach ($item_namer as $key => $value){
//print_r($medicine_typer[$key]);//output CABA
//print_r($quantityr[$key]);//output 2
//print_r($pricer[$key]);//output 2020
$medicine_typer =$medicine_typer[$key];
$quantityr =$quantityr[$key];
$pricer =$pricer[$key];
$db2->query('INSERT INTO dpr_medicine_return(medicine_type,quantity,price)
VALUES ("'.$medicine_typer.'","'.$quantityr.'","'.$pricer.'")');
$i++;
}
}
you are revaluing variable in the loop so when the loop run for 2 time the time it didn't find those array variable but now they are not array use this code
$medicine_typer2 =$medicine_typer[$key];
$quantityr2 =$quantityr[$key];
$pricer2 =$pricer[$key];
$itemidr2 =$item_idr[$key];
now use these variable in your query