0

我有一个名为“ Serials ”的表,其中包含 5 个公共 序列、代码、名称、兑换、兑换日期

我正在使用此查询从该表中选择一些字段:

$query = "SELECT `Name`,`Redeemed`,`Redeem_date` FROM `Serials` WHERE `Serial` = '$serial' AND `Code` = '$code'";
$db->setQuery($query);
$db->query();

但我不知道如何在以下变量中传递这些值,以便稍后在 if 语句中使用它们

$name= //retured value from column Name
$redeemed= //retured value from column Redeemed
$redeem_date= //retured value from column Redeem_date
4

3 回答 3

0

像这样..

// Your query here..
$query = "SELECT `Name`,`Redeemed`,`Redeem_date` FROM `Serials` WHERE `Serial` = '$serial' AND `Code` = '$code'";
$db->setQuery($query);
$results = $db->query();

//fetch data and stored into variables
while($row = fetch_array($results)){
  $name = $row['Name'];
  $redeemed = $row['Redeemed'];
  $redeem_date = $row['Redeem_date'];
}
于 2013-04-02T13:53:21.267 回答
0

尝试这样的事情:

<?php
$result = $db->query("SELECT `Name`,`Redeemed`,`Redeem_date` FROM `Serials` WHERE `Serial` = '$serial' AND `Code` = '$code'");
while (list($name, $redeemed, $redeem_date) = $result->fetch(PDO::FETCH_NUM)) {
 // DO SOMETHING
}
?>
于 2013-04-02T13:53:56.187 回答
0
while ($row = $db->fetch()) {

$name= $row['name'];
$redeemed= $row['redeemed'];
$redeem_date= $row['redeem_date'];

}

这个可能会获取您的结果并分配给 vars

于 2013-04-02T13:56:41.273 回答