-1
どの日付でもダブルの予約がないようにしたいと思っていました。私はデータを呼び出すためにselect distinctとinsert queryの両方を使用しました。それでもデータは重複している可能性があります。フィールドのセットユニークなフィールド/ため2つのクエリが区別され、挿入にエラーが発生する
<?php
error_reporting(0);
$con=mysqli_connect("localhost","root","","jpn");
[email protected]$_POST["rol_no"];
[email protected]$_POST["ic"];
[email protected]$_POST["tarikh"];
[email protected]$_POST["tarikhakhir"];
[email protected]$_POST["bilangan"];
[email protected]$_POST["sebab"];
//insertion data tempahan
$sql="INSERT INTO tempahan(ic,start,end,bil,title) VALUES ('$ic','$start','$end','$bil','$title')
ON DUPLICATE KEY
UPDATE
ic='$ic'
,start ='$start'
,end='$end'
,bil='$bil'
,title='$title'
";
$result=mysqli_query($con,$sql);
if($row=mysqli_fetch_array($con,$result))
{
$rol_no=$row[0];
$ic=$row[1];
$start=$row[2];
$end=$row[3];
$bil=$row[4];
$title=$row[5];
}
//distinct data to avoid duplicate for date
$sql2= "SELECT DISTINCT start, end
FROM tempahan
ORDER BY start, end";
if(mysqli_query($con,$sql2))
{
echo "<script>alert('duplicate tarikh')</script>";
}
?>
[mysqli_fetch_array()のRTFM]](http://php.net/manual/en/mysqli-result.fetch-array.php) –