doukun0888 2014-05-05 21:59
浏览 31
已采纳

如何在另一个php页面上使用选定的链接值

I'm new with questions and generally with "Stack Overflow", so forgive me if it is not formatted well.

So, I have problem with transferring some informations from one page to another. It is a value of <a> tag from an php while loop.

At the moment I have something like this:

$query = mysql_query("SELECT DISTINCT `a`.`id`,`o`.`first_name` , `o`.`last_name` , `a`.`name` FROM `owner` AS `o` , `animal` AS `a` WHERE `o`.`id` = `a`.`fk_current_owner` AND `o`.`fk_user` = '".$_SESSION['user_id']."'");

while($row = mysql_fetch_assoc($query)){
    $pet_id = $row['id'];
    $first_name = $row['first_name'];
    $last_name = $row['last_name'];
    $pet_name = $row['name'];


    echo 'Owner: <strong>'.$first_name.' '.$last_name.'</strong> ';
    echo 'Pet: <strong><a href="viewPet.php" id="'.$pet_id.'">'.$pet_name.'</a></strong><br>';
}

So you can assume that this will display names of pets that logged user got. So I linked their names and I need to get ID of selected name on another page so I can display details of pet on page viewPet.php.

  • 写回答

2条回答 默认 最新

  • dongpai2754 2014-05-05 22:38
    关注

    You can also send the pet id along as a GET parameter with the link.

    echo '<a href="viewPet.php?id='.$pet_id.'" id="'.$pet_id.'">'.$pet_name.'</a>';
    

    On the viewPet.php page you'd access it by $_GET['id']

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)