用于更新表的php链接触发器

时间:2014-01-23 06:59:56

标签: php hyperlink

我创建了一个代码,以便按照年龄排序按宠物名称排序。我如何对其进行编码,以便一旦用户点击petname,它就会从petcatalog表中使用petid更新viewpet列,这样一旦将它们定向到viewbio.php页面,viewbio.php页面就会有petid到检索特定宠物的信息?下面是代码。一旦用户点击该宠物的名字,我就无法将其与宠物特定的petid一起送到UPDATE viewpet列。

这是我的代码:

$sessionid = $_SESSION['uid'];
$info = $conn->prepare("SELECT `petname`,`age`,`petid` FROM `data` WHERE id = :id ORDER       BY `age` DESC");
$info ->bindParam(':id', $sessionid , PDO::PARAM_INT);
$info->execute();


 $rank = 0;
 $last_score = false;
 $rows = 0;


 while ($userinfo = $info->fetchobject()) {

$rows++;
if( $last_score!= $userinfo->age ){
  $last_score = $userinfo->age;
  $rank++;
}


echo "<b>$rank</b> . <a href='viewbio.php'> $userinfo->petname </a> &nbsp&nbsp&nbsp        <b>Age:</b>   $userinfo->age &nbsp&nbsp&nbsp <b>Pet ID:</b> $userinfo->petid    </br>";

if (isset($_GET['viewbio.php']))
{
$sessionid = $_SESSION['uid'];

$q = $conn->prepare("UPDATE petcatalog SET viewpet = :viewwrestler WHERE id = :id");
$q->bindParam(':id', $sessionid, PDO::PARAM_INT);                                                  
$q->bindParam(':viewpet',$userinfo->petid , PDO::PARAM_INT);                                                   
$q->execute();
}

1 个答案:

答案 0 :(得分:1)

您无需更新点击即可获得petid。你可以预加载它。我为你准备了一个场景。

<强> petlist.php

<?php
$sessionid = $_SESSION['uid'];
$info = $conn->prepare("SELECT `petname`,`age`,`petid` FROM `data` WHERE id = :id ORDER       BY `age` DESC");
$info ->bindParam(':id', $sessionid , PDO::PARAM_INT);
$info->execute();


 $rank = 0;
 $last_score = false;
 $rows = 0;


 while ($userinfo = $info->fetchobject()) {

$rows++;
if( $last_score!= $userinfo->age ){
  $last_score = $userinfo->age;
  $rank++;
}


echo "<b>$rank</b> . <a href='viewbio.php?petid='$userinfo->petid> $userinfo->petname </a> &nbsp&nbsp&nbsp        <b>Age:</b>   $userinfo->age &nbsp&nbsp&nbsp <b>Pet ID:</b> $userinfo->petid    </br>";

<强> viewbio.php

$pet_id = $_GET["petid"];
$info = $conn->prepare("SELECT * FROM `pet_info_table` WHERE petid = :pet_id");
$info ->bindParam(':pet_id', $pet_id , PDO::PARAM_INT);
$info->execute();