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 AAAex 2).
AAA AAA AAA BBB AAAi 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.
精彩评论