The PHP MySQL database finds the fields of the most recent same content and subtracts the output difference with their ID

Source: Internet
Author: User
Tags php mysql
PHP MySQL database to find the most recent fields of the same content, with their ID subtraction output difference
Table MYDB1, fields: (ID, number of periods, number 1, number 2, number 3), each issue has three numbers (such as 356). 3 of these are (number 1 field), 5 is (number 2 field), 6 is (number 3 field). Wait until the N-period lottery number appears again 356, use this 356 ID minus the previous 356 ID output difference.

$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 '];}}

Please write a detailed written, Thank you PHP MySQL

Share to:


------Solution--------------------
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
------Solution--------------------
SELECT a.ID, a.id-b.id as Sub
From MYDB1 A, mydb1 b
WHERE A. Number 1 = B. Number 1
and a. Number 2 = B. Number 2
and a. Number 3 = B. Number 3
Having sub >0
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.