我如何从PHP中的数据库中获取特定值?

时间:2012-10-19 06:54:40

标签: php html mysql

    $sql="Select chanceNo From gm_gacha_token1 where token_code='$mytoken'";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);

Langauge:PHP

我想要实现的是,我希望得到一个机会值的值。我怎样才能获得该值并将其存储到cookie / sesison并在下一页显示?

任何想法,下一步或下一行代码是什么?

2 个答案:

答案 0 :(得分:1)

Page1:

session_start();

$query = mysql_query("Select chanceNo From gm_gacha_token1 where token_code='$mytoken' LIMIT 1");

if (mysql_num_rows($query) > 0){
$result = mysql_fetch_assoc($query);
$_SESSION['chanceNo'] = $result['chanceNo'];
// done, maybe header('location: page2.php'); ?
} else {
 // no result
}

2页:

session_start();
$chanceNo = $_SESSION['chanceNo'];
echo $chanceNo;

答案 1 :(得分:-2)

试试这个...

   $sql="Select chanceNo From gm_gacha_token1 where token_code='$mytoken' LIMIT 1"; 
   $result = mysql_query($query) or die (mysql_error());

 while($rows = mysql_fetch_assoc($result))
    {
      echo $rows[chanceNo];
    }
相关问题