Heim >Backend-Entwicklung >PHP-Tutorial >php mysql数据库找出最近相同内容的字段,用它们的id相减输出差
表mydb1、字段:(id、期数、号码1、号码2、号码3),每期开奖号有三个数字(如356)。其中的3是(号码1字段)、5是(号码2字段)、6是(号码3字段)。等到n期后开奖号又出现356时就用这次356的id减去前一次356的id输出差。
$array = array();
while($row = mysql_fetch_assoc($result)){
if(in_array($row['content'],$array)){
$a = $row['id'];
foreach($array as $key =>$content){
if($row['content']==$content){
$b = $key;}}}else{
$array[$row['id']] = $row['content'];}}
求各位高手详细写一写, 谢谢
select (T2.id - T1.id)from table1 T1,table2 T2 where T1.num1=T2.num1 AND T1.num2=T2.num2 AND T1.num3=T2.num3
SELECT a.id, a.id - b.id AS sub FROM mydb1 a, mydb1 b WHERE a.号码1 = b.号码1 AND a.号码2 = b.号码2 AND a.号码3 = b.号码3 HAVING sub >0
麻烦再详细点呗
这样写对吗?怎么输出哇?
$result = mysql_query("SELECT a.id, a.id - b.id FROM mydb1 a, mydb1 b WHERE a.hao1 = b.hao1 && a.hao2 = b.hao2 && a.hao3 = b.hao3 HAVING sub >0");
while($row = mysql_fetch_array($R1))
{
echo $row['']