开发者

SQL find duplicate data

开发者 https://www.devze.com 2023-04-13 05:23 出处:网络
can you help me to solve this problem. im using PHP开发者_Python百科 and MySQL. i have sql query :

can you help me to solve this problem.

im using PHP开发者_Python百科 and MySQL.

i have sql query :

$qx=mysql_query("SELECT ORCASENO,ORORDNO From order_break WHERE ORCASENO='$bcode' AND ORDEST='$dest'");

 while($rx=mysql_fetch_array($qx))
        {
            echo $ORORDNO_rx= $rx['ORORDNO'];

        }

this code sample able to generates two types of outputs.

ex: 1).

AAA

AAA

AAA

AAA

AAA

ex 2).

AAA

AAA

AAA

BBB

AAA

i need to generate error on example 2 because it containing two/more different values for $ORORDNO_rx; like BBB

please help me to solve this.

thanks in advance.


You can do this in way:

$qx=mysql_query("SELECT ORCASENO,ORORDNO From order_break WHERE ORCASENO='$bcode' AND ORDEST='$dest'");

$array = array();
while($rx=mysql_fetch_array($qx))
   $array[] = $rx['ORORDNO'];

if (count(array_unique($array)) > 1)
   echo 'Error';
else
{
   foreach($array as $value)
      echo $value;
}


In your SQL query you could add count(distinct(ORORDNO)) in your select. Then do a check for > 1 in your php.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号