开发者

SQL find duplicate data

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜