一个表中匹配的行

时间:2014-07-19 16:17:14

标签: php mysql

我向我展示了我的问题和努力。

我有一个桌上学生。

id   | name   | age | email | address | date
------------------------------
 1   | abc    | 20  | *abc@gmail.com*     |  street number10 | 14/07
------------------------------
 5   | abc    | 25  | *abc@gmail.com*     |  street number12 | 15/07
------------------------------
 8   | abc    | 25  | *abc@gmail.com*     |  street number10 | 15/07
------------------------------
12   | umnnn  | 20  | *umnn@gmail.com*    |  street number11 | 15/07
------------------------------
14   | umnnn  | 20  | *umnn@gmail.com*    |  street number10 | 14/07
------------------------------
15   | umnnn  | 25  | *umnn@gmail.com*    |  street number12 | 15/07
------------------------------
16   | hjk    | 25  | *hjk@gmail.com*     |  street number14 | 15/07
------------------------------
20   | hjk    | 20  | *hjk@gmail.com*     |  street number14 | 15/07
------------------------------
21   | hjk    | 23  | *hjk@gmail.com*     |  street number10 | 15/07

我希望根据电子邮件匹配行,并希望获得无与伦比的记录与日期

示例:电子邮件ID hjk@gmail.com

第9行(id = 21)应与第8行(id = 20)匹配,并且只应给出第9行的不匹配值,表示id = 21,age = 23,address = street number10的值,不应该是其他属性。

喜欢(更新到15/07:id = 21,年龄= 23,街道号码10)

第8行(id = 20)应与第7行(id = 16)匹配,并且只应给出第8行的不匹配值,表示id = 20,age = 20的值。

***赞(更新至15/07:id = 20,年龄= 20 * * *

**和其他电子邮件ID,操作将如上* *

我的努力是:

    <?php
$con=mysqli_connect("localhost","root","","sociale");

if(! $con )

{

  die('Could not connect: ' . mysqli_error());

}

$email=$_SESSION["email"];

$sql = "SELECT * FROM  student where email='{$email}' and year='$year'";

$retval = mysqli_query( $con, $sql );


if(! $retval )

{
  die('Could not get data: ' . mysqli_error());

}

$cnt = mysqli_num_rows ( $retval );

if($cnt <=1)
{

   echo 'No Updates.';

}

else
{


   $retval = mysqli_query( $con, $sql );

   $except_last = array();

   while($row = mysqli_fetch_assoc($retval))

  {

      $except_last[] = $row;

   }

  array_pop($except_last);



   $retval = mysqli_query( $con, $sql );

   $except_first = array();

   while($row = mysqli_fetch_assoc($retval))

  {

      $except_first[] = $row;



   }

   array_shift($except_first);


   for($i=0;$i<count($except_first);$i++)

{


        $result = array_diff_assoc($except_first[$i], $except_last[$i]);

 $c=0;

        echo "<BR>";        

        foreach($result as $key=>$value){

        $c++;

        echo $key." = ".$value;

        if($c<count($result)) 

        {

                                  echo ", &nbsp; ";
       } 

   }

}

}

mysqli_close($con);

?>

它提供了无与伦比的价值。但我也想约会。

例如电子邮件hjk@gmail.com:

我想:更新为 15/07 :id = 21,年龄= 23,街道号码10

它给出:id = 21,年龄= 23,街道号码10(未给出日期)

请帮忙。

0 个答案:

没有答案
相关问题