「test」というデータベースを作成し、「biodata」というテーブルを作成しました。「名前」「年齢」「説明」という 3 つの列を biodata テーブルに作成しました。次に、配列の結果を各列に格納する方法を説明します。
以下は完全なコードです...
<?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);
?>