大家好我有问题,我想从循环中删除重复值 例如。
我有4条记录, 它必须是从我的输出显示4条记录,问题是,它显示了16条记录,这就是我需要从循环语句中删除重复的原因
请参阅下面的代码
来自提交
<input type='text' value='<?php echo "$row[partyid]"; ?>' name='phonenum[]' readonly />
for ($i=0; $i<sizeof($phonenum);$i++)
{
$sql = "SELECT *
FROM
$table2,
$table3
WHERE
$table2.billdate = '$date'
AND $table3.tel_three LIKE '%$phonenum[$i]%'
";
<?php if( $rs == null ):?>
<tr>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
<td align='center'><font size=1>0</font></td>
</tr>";
<?php else:?>
<?php while( $row = mysql_fetch_assoc($rs) ):
?>
<tr>
<form action='flookup.php' method='post'>
<td align='center'><?php echo "<font size=1>".$row['billdate']."</font>"; ?></td>
<td align='center'><?php echo "<font size=1>".$row['calldate']."</font>"; ?></td>
<td align='center'><?php echo "<font size=1>".$row['partyid']."</font>"; ?></td>
<td align='center'><?php echo "<font size=1>".$row['billedamount']."</font>"; ?></td>
<td align='center'>
<?php echo "<font size=1>".$row['partyid']."</font>"; ?>
<input type='hidden' value="<?php echo $row['partyid']; ?>" name='phonenum' readonly />
</td>
<td align='center'><?php echo "<font size=1>".$row['value']."</font>"; ?>
<input type='hidden' value="<?php echo $row['value']; ?>" name='sipvalue' readonly />
<td align='center'><input type='text' value="<?php echo $row['value']; ?>" name='value' readonly />
</td>
</tr>
<?php endwhile;?>
<?php endif;
}
?>
答案 0 :(得分:0)
您需要修改SQL语句以在$ table2和$ table3
之间添加连接条件$sql = "SELECT *
FROM
$table2,
$table3
WHERE
$table2.billdate = '$date'
AND $table3.tel_three LIKE '%$phonenum[$i]%'
AND $table2.something = $table3.something
";