Php 显示表中的特定行

Php 显示表中的特定行,php,mysql,Php,Mysql,我有一张桌子 id | name | age | emailid ------------------------------- 1 | abc | 24 | abc@gmail.com 2 | abc | 35 | abc@gmail.com 3 | abc | 23 | abc@gmail.com 我的php代码是: <?php require"connection.php"; $email=$_SESSION["email"]; $qry=mysql_quer

我有一张桌子

id | name | age | emailid
-------------------------------
1  | abc  | 24  | abc@gmail.com
2  | abc  | 35  | abc@gmail.com
3  | abc  | 23  | abc@gmail.com
我的php代码是:

<?php
require"connection.php";

$email=$_SESSION["email"];

$qry=mysql_query("select * from user_new_history where email='$email' order by id ASC") or die(mysql_error());

while($qry1=mysql_fetch_array($qry))
{
    if($count<1)
    {
        echo $id;
    }
}
?>

您使用电子邮件查找用户,并且您有3个用户名和电子邮件相同的用户

您必须设置唯一的“电子邮件”和“姓名”字段

然后您可以找到用户。

在SQL中执行此操作:

select * from user_new_history where email='$email' order by id ASC LIMIT 1,1
试试这个:

<?php
  require"connection.php";

  $email=$_SESSION["email"];

  $qry=mysql_query("select * from user_new_history where email='$email' order by id ASC") or die(mysql_error());
  $count = 1;
   while($qry1=mysql_fetch_array($qry))
   {
     if($count == 2)
     {
       echo $id;
     }
     $count ++;
   }
?>

不要忘记代码中的缩进。因为您还不清楚自己想要什么,所以我编写了这条SQL语句,它将提供您想要的,但可能不是您想要的<代码>$qry=mysql\u查询(“从id='2''的用户\u新建\u历史中选择*)或死亡(mysql\u错误())如果ID是唯一的,则使用ID查找用户。当您尝试通过电子邮件查找用户时,电子邮件必须是唯一的。