我需要将类中调用的数组值存储为数据库中的对象。编码
<?php
echo "BEST SELECTED POPULATION";
debug(GA::select($ga->population,'total',3)); //The best
$asma[]=GA::select($ga->population,'total',3); //The best
}
print_r($asma);
?>
$array1
是我得到输出值的数组,这个数组是动态的,它的值的数量增加取决于用户输入。
<?php
include('config.php');
//database connection
//query
$new_array = array($asma);
foreach($new_array as $key => $value) {
foreach ( $value as $ind => $data ) {
/*
You now have access to field values like this
$data['Voltage']
$data['Number']
$data['Duration']
*/
// query makes no sense 3 fields mentioned and 4 parameters given???
// you will have to decide which of the fields from $data[] you want to load
// to which fields in the database.
$sql = "INSERT INTO ga (gaid,fe,fe1,timestamp) VALUES ('', '$key', '$value', '".date("Y-m-d H:i:s")."')";
$stmt = mysql_query($sql) or die(mysql_error());
} // endforeach
} // endforeach
?>
如果我使用上面的代码进行插入,它不会显示错误,但它会ga
像这样在表中输入值
gaid fe fe1 timestamp
1 0 array -
上面的代码我用来在我的表中插入ga
输出print_r($asma);
Array (
[0] => Array (
[0] => H Object (
[Voltage] => 12
[Number] => 1
[Duration] => 3
)
[1] => H Object (
[Voltage] => 26
[Number] => 4
[Duration] => 8
)
[2] => H Object (
[Voltage] => 26
[Number] => 4
[Duration] => 8
)
)
[1] => Array (
[0] => H Object (
[Voltage] => 18
[Number] => 1
[Duration] => 4
)
[1] => H Object (
[Voltage] => 38
[Number] => 4
[Duration] => 10
)
[2] => H Object (
[Voltage] => 36
[Number] => 2
[Duration] => 8
)
)
)
我需要将数据库中的所有值存储在上面的输出 6 值中。
这是桌子
gaid fe fe1 fe2 timestamep