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>

        插入前检查重复项

        Check for duplicates before inserting(插入前检查重复项)

              <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 Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)

                    <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'>

                        • <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>
                            <tbody id='8KtSY'></tbody>