我有一個包含50個索引值的數組。 THA陣列,我print_r($result);
後得到的一部分是從數組中提取數據並保存在數據庫中
Array
(
[0] => Array
(
[ClassScheduleID] =>
[Location] => Array
(
[Latitude] =>
)
[ClassDescription] =>
(
[ImageURL] =>
[Level] =>
(
[Name] =>
)
[Program] =>
(
[Name] =>
)
)
[Staff] => Array
(
[FirstName] =>
)
)
[1] => Array
(
[ClassScheduleID] =>
[Location] => Array
(
[Latitude] =>
)
[ClassDescription] =>
(
[ImageURL] =>
[Program] =>
(
[Name] =>
)
)
[Staff] => Array
(
[FirstName] =>
)
)
[2] => Array
(
[ClassScheduleID] =>
[Location] => Array
(
[Latitude] =>
)
[ClassDescription] =>
(
[ImageURL] =>
[Program] =>
(
[Name] =>
)
)
[Staff] => Array
(
[FirstName] =>
)
)
)
我已經通過下面的代碼(該代碼的一部分)
if (!empty($result))
{
foreach ($result as $res)
{
$classscheduleid = $res['ClassScheduleID'];
if(isset($res['Location']))
{
$l_latitude = $res['Location']['Latitude'];
}
if(isset($res['ClassDescription']))
{
$c_img = $res['ClassDescription']['ImageURL'];
}
if(isset($res['ClassDescription']['Level']))
{
$c_l_name = $res['ClassDescription']['Level']['Name'];
}
if(isset($res['ClassDescription']['Program']))
{
$c_p_name = $res['ClassDescription']['Program']['Name'];
}
if(isset($res['Staff']))
{
$s_firstname = $res['Staff']['FirstName'];
}
$sql = "INSERT INTO class_detail (classscheduleid,l_latitude,c_img,c_l_name,c_p_name,s_firstname) VALUES ('".$classscheduleid."','".$l_latitude."',,'".$c_img."','".$c_l_name."','".$c_p_name."','".$s_firstname."')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
}
即我面臨的問題是提取從陣列中的數據當我試着在數據庫中插入值時,它不插入前8個索引值,它開始從[9]位置保存值。我正確地獲取所有數據,因爲我通過echo所有變量進行了檢查。任何人都可以告訴我如何在數據庫中正確保存數組的值
這是因爲'ClassScheduleID'在前8個結果中爲NULL。使classscheduleid列接受空值 – manoj 2015-03-19 06:31:46
@manoj ClassScheduleID不爲空,我打印結果,我得到每個數組的結果 – lyra 2015-03-19 06:33:50
你得到多少結果 – 2015-03-19 06:54:11