php mysql資料庫找出最近相同內容的欄位,用它們的id相減輸出差

來源:互聯網
上載者:User
表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['']

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.