0

我一直试图让每个人的 id 都被列入某个事件。哪个有效。但是,由于某种原因,这不起作用。以前做的时候。我在测试时意识到,当我在 while($userRes->fetch()) 之后立即放置 $userRes->close 时,$user = getUser($connection, $id) 有效,但是当它在循环之外时它不会不行。这是我的代码:

$userQuery = "SELECT person_id FROM RosterPeopleEvent WHERE news_id=?;";
$userRes = $connection->prepare($userQuery);
$userRes->bind_param('i', $eventID);
$userRes->execute();
$userRes->bind_result($id);

while ($userRes->fetch()){
    $user = getUser($connection, $id);
    if ($user == $_SESSION["uid"]){
        $p->addContent("You have volunteered for the BBQ <a href=roster.php?rosterid=1&personid=$id&eventid=$eventID&class=remove rel=external>Remove</a>, ");  
    }
    else{
        $p->addContent("$user has volunteered for the BBQ <a href=roster.php?rosterid=1&personid=$id&eventid=$eventID&class=remove rel=external>Remove</a>, "); 
    }                           
}
$userRes->close();      
4

1 回答 1

0

固定版本:

$userQuery = "SELECT person_id FROM RosterPeopleEvent WHERE news_id=?;";
$userRes = $connection->prepare($userQuery);
$userRes->bind_param('i', $eventID);
$userRes->execute();
$userRes->bind_result($id);
$userRes->store_result();

while ($userRes->fetch()){
    $user = getUser($connection, $id);
    if ($user == $_SESSION["uid"]){
        $p->addContent("You have volunteered for the BBQ <a href=roster.php?rosterid=1&personid=$id&eventid=$eventID&class=remove rel=external>Remove</a>, ");  
    }
    else{
        $p->addContent("$user has volunteered for the BBQ <a href=roster.php?rosterid=1&personid=$id&eventid=$eventID&class=remove rel=external>Remove</a>, "); 
    }                           
}
$userRes->close();
于 2013-11-12T21:35:57.897 回答