English 中文(简体)
设置 MySQL 数据库中重复条目的警告
原标题:setting up warning for duplicate entries in MySQL database

我有一张5个列的桌子 ID, 姓名, 姓, 公司 & amp; 标题 。

所以,我现在要做的是检查提交过程中的重复条目,比较名称和姓氏组合匹配。这应该导致提醒重复条目,并选择继续将其保存到数据库,或者取消内容的提交。

提前感谢。

问题回答

您有这个选项 :

  • setup a conventional index on "(name, surname)"
  • before each insert, check if the "(name, surname)" combination already exists
  • if NOT EXISTS, do the insert normaly [here it is up to you to consider the risk that in this 1ms time sb else might have done the same insert]
  • if EXISTS AND force mode, add the row anyway
  • if EXISTS AND NOT force mode, proceed to the client according to your specifications
  • if the client wants to save anyway, repeat operation in force mode.

如果您真的认为这值得, 这里的替代方案是插入行, 并检查是否有前面的行。 如果客户端想要保留记录, 请留下它, 否则删除它 。

参考参考值

我试过了,但还没有弄明白 问题中提到的选择性选择法。

$query = "INSERT INTO phptablo (Name, Surname, Company, Title) VALUES ( $name ,  $surname ,  $company ,  $title )";

$sql = "SELECT Name AND Surname FROM phptablo WHERE Name =  $name  AND Surname=  $surname ";

$result = mysql_query($sql);
$count = mysql_num_rows($result);
$row = mysql_fetch_array($result);

echo "$sql" .  <br/><br/> ; 

echo "$result" .  <br/><br/> ;

if ($count==0)
{
    if (!mysql_query($query)) 
    {
        die( Error:   . mysql_error());
    }

    echo "Successful Entry!";
}
else 
{
    echo "Duplicate Entry found!";
}

我对 php & amp; MySQL 的 php < general\\ em\ \ / ems\ / strong > 到 php & amp; MySQL 所以无法真正利用您非常感激的答案。 是否有机会添加一些代码来让我选择保存它?

我现在所处的位置是,如果检测到重复条目,输入没有保存到数据库中,否则它就会立即存储。如果我所写的代码不能真正被修改以保存重复,我也可以在保存后用某种屏幕显示复制件,这样它们就可以被编辑、删除等等。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签