dsfsdf7852 2013-04-24 11:21 采纳率: 100%
浏览 69

尝试获取特定外键的信息

i am new in php and mysql. I am trying to fetch information from one of my table. Just give you the information about my table. Name of my table is leave.it contaning one foreign key namely leaveId.

    lid     empname     username    nod     date     reason  action leaveID 
    ===     =======     ========    ===     =====    ======  ====== =======
     1      Maxwell       max        1       2012     Null   Denied    3
     2      Ponting      punter      1       2011     Null   Denied    4
     3      Ponting      punter      2       2011     xam    Accepted  4
     4      Taylor       tayl        1       2011     Null   Accepted  1

now as example is there any sql query to retrieve only the information of Pointing whom leaveId is 4. I wrote the following query..

$leave = mysql_query("SELECT * FROM `leave` where leaveID = $user ");

but it only return the 2nd row associated with the number 4 leaveId where it should return the both 2nd and 3rd row,isn't it?? . Actually i am not sure...if it is wrong then give me the right answer to(as example) how can i fetch the information of ponting whom leaveID is 4.

  • 写回答

1条回答 默认 最新

  • duanbeng8872 2013-04-24 11:30
    关注

    you need to get your rows with a while loop

    $leave = mysql_query("SELECT * FROM `leave` where leaveID = $user ");
    while ($row = mysql_fetch_array($leave, MYSQL_NUM)) {
        printf(" ID:", $row[0], "empname ", $row[1]);  
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题