douyuepi6485 2015-12-23 04:05
浏览 70

使用PHP和MySQL查询表中的重复值

I need some help regarding MySQL query for checking duplicate value from table using MySQL and PHP. Let me to explain my table structure and conditions

db_product_info

pro_id     product_name      product_code      status

The above are my columns in db_product_info table.

conditions:

1-> When table has no value the data should entry in table.

2-> In same product name only same product code will be inserted for once/multiple time in table.If input will different code for same product name (for more than one enrty) it should be checked and return the validation message.

3- Duplicate of product_code will be checked according to the product_name as explained above.means for same product_name only same product_code should entry multiple time but this product_code should not used for any other product_name .

Let me to explain my code below.

 require_once("../include/dbconfig.php");
    $result=array();
    $fields=array("Product_name","status","product_code");
    $tablename=PREFIX."product_info";
$values=array($_POST['product_name'],$_POST['status'],$_POST['product_code']);
    $id=db_insert($tablename,$values,$fields);
                   if($id){
                $result[0]["msg"]="Added successfully";
                $result[0]['id']=$id;
                echo json_encode($result);
            }else{
                header("HTTP/1.0 401 Unauthorized");
                $result[0]["msg"]="Unable to add try again";
                $result[0]["data"]=$values;
                echo json_encode($result);
            }

Please help me to resolve this problem.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向