我创建了一个名为“test”的数据库并创建了一个名为“biodata”的表。我在生物数据表中创建了 3 个名为“名称”“年龄”和“描述”的列。现在如何将我的数组结果存储到每一列中。
下面是完整的代码...
<?php
$ip = "localhost";
$username = "root";
$password = "";
$dbname = "test";
$res = mysql_connect($ip,$username,$password);
if(!$res)
{
echo "DB Connection Failed.";
exit;
}
if(!mysql_select_db("test"))
{
echo "NOT SELECTED";
exit;
}
$company = array(
'Record1'=>array('Shabbir',26,'Designer'),
'Record2'=>array('Burhan',24,'Architecture'),
'Record3'=>array('Huzeifa',20,'Accountant'),
);
foreach ($company as $employees=>$details){
echo '<strong>'.$employees.'</strong><br>';
foreach($details as $employeeinfo){
echo $employeeinfo.'<br>';
}
}
$sql = "INSERT INTO biodata (Name, Age, Description) VALUES ($employeeinfo[0], $employeeinfo[1], '$employeeinfo[2]')";
mysql_query($sql);
?>