1. <i id='ox9uu'><tr id='ox9uu'><dt id='ox9uu'><q id='ox9uu'><span id='ox9uu'><b id='ox9uu'><form id='ox9uu'><ins id='ox9uu'></ins><ul id='ox9uu'></ul><sub id='ox9uu'></sub></form><legend id='ox9uu'></legend><bdo id='ox9uu'><pre id='ox9uu'><center id='ox9uu'></center></pre></bdo></b><th id='ox9uu'></th></span></q></dt></tr></i><div id='ox9uu'><tfoot id='ox9uu'></tfoot><dl id='ox9uu'><fieldset id='ox9uu'></fieldset></dl></div>

      <small id='ox9uu'></small><noframes id='ox9uu'>

    2. <tfoot id='ox9uu'></tfoot>

          <bdo id='ox9uu'></bdo><ul id='ox9uu'></ul>
        <legend id='ox9uu'><style id='ox9uu'><dir id='ox9uu'><q id='ox9uu'></q></dir></style></legend>

        插入前检查重复项

        时间:2023-12-01

              <small id='z20FD'></small><noframes id='z20FD'>

              <tfoot id='z20FD'></tfoot>
              1. <i id='z20FD'><tr id='z20FD'><dt id='z20FD'><q id='z20FD'><span id='z20FD'><b id='z20FD'><form id='z20FD'><ins id='z20FD'></ins><ul id='z20FD'></ul><sub id='z20FD'></sub></form><legend id='z20FD'></legend><bdo id='z20FD'><pre id='z20FD'><center id='z20FD'></center></pre></bdo></b><th id='z20FD'></th></span></q></dt></tr></i><div id='z20FD'><tfoot id='z20FD'></tfoot><dl id='z20FD'><fieldset id='z20FD'></fieldset></dl></div>

                  <tbody id='z20FD'></tbody>
                <legend id='z20FD'><style id='z20FD'><dir id='z20FD'><q id='z20FD'></q></dir></style></legend>
                  <bdo id='z20FD'></bdo><ul id='z20FD'></ul>

                  本文介绍了插入前检查重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在插入数据库之前,我使用以下代码检查重复项.对我来说,只有当 namedescriptionpricecity 时,重复才被视为重复>enddate 匹配.

                  Before inserting into the database, I'm using the following code to check for duplicates. To me, a duplicate is only considered a duplicate when name, description, price, city, and enddate match.

                  foreach($states_to_add as $item) {
                      $dupesql = "SELECT 
                                      COUNT(*) 
                                  FROM 
                                      table 
                                  WHERE 
                                      (   
                                          name = '$name' 
                                          AND description = '$description' 
                                          AND manufacturer = '$manufacturer' 
                                          AND city ='$city' 
                                          AND price = '$price' 
                                          AND enddate = '$end_date'
                                      )";
                  
                      $duperaw = mysql_query($dupesql);
                  
                      if($duperaw > 0) {
                          echo nl2br("$name already exists in $city 
                  ");
                      } 
                      else {
                          $sql = "INSERT INTO table (..... (here go the values to be inserted)
                          ....
                  

                  每个值都是在运行此检查之前定义的,我的结果总是在项目已经存在时返回.我转储了dupesql"并将命令复制/粘贴到 phpmyadmin 中,返回计数为 0.

                  Each value is defined prior to running through this checking, my result always comes back as item already exists. I dumped "dupesql" and copy/pasted the command into phpmyadmin which comes back with count 0.

                  推荐答案

                  您想要执行以下操作:

                  $dupesql = "SELECT * FROM table where (name = '$name' AND description = '$description' AND manufacturer = '$manufacturer' AND city ='$city' AND price = '$price' AND enddate = '$end_date')";
                  
                  $duperaw = mysql_query($dupesql);
                  
                  if (mysql_num_rows($duperaw) > 0) {
                    //your code ...
                  }
                  

                  查看这里了解更多信息.

                  这篇关于插入前检查重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 PHP 中的字符串中删除重复项 下一篇:如何在 PHP 中搜索数组中的多个值?

                  相关文章

                    <bdo id='8KtSY'></bdo><ul id='8KtSY'></ul>
                  <legend id='8KtSY'><style id='8KtSY'><dir id='8KtSY'><q id='8KtSY'></q></dir></style></legend>

                      <tfoot id='8KtSY'></tfoot>

                      <small id='8KtSY'></small><noframes id='8KtSY'>

                    1. <i id='8KtSY'><tr id='8KtSY'><dt id='8KtSY'><q id='8KtSY'><span id='8KtSY'><b id='8KtSY'><form id='8KtSY'><ins id='8KtSY'></ins><ul id='8KtSY'></ul><sub id='8KtSY'></sub></form><legend id='8KtSY'></legend><bdo id='8KtSY'><pre id='8KtSY'><center id='8KtSY'></center></pre></bdo></b><th id='8KtSY'></th></span></q></dt></tr></i><div id='8KtSY'><tfoot id='8KtSY'></tfoot><dl id='8KtSY'><fieldset id='8KtSY'></fieldset></dl></div>