2015-10-19 90 views
-2

我很難理解會議。我想在會話中存儲card_id,我該怎麼做?與會議合作

$resultSet = $mysqli->query ("SELECT value FROM card_credit 
WHERE card_id= (select distinct card_id 
       from Raw where 
       id = (select max(b.id) from Raw as b))"); 

if($resultSet->num_rows != 0){ 

while($rows = $resultSet->fetch_assoc()) 
    { 
     $card_id = $rows['value']; 

     echo "<p>Saldo: $card_id"; 
+0

使用此$ _SESSION [ 「card_id的」] = $ card_id的; –

+0

使用'session_start()','$ _SESSION []'和PHP文檔http://php.net/manual/en/book.session.php –

+0

您的示例與會話無關。唯一相關的行(答案的起點)是'$ card_id =' –

回答

0

試試這個代碼利用session_start

<?php 
// Start the session 
session_start(); 
$resultSet = $mysqli->query ("SELECT value FROM card_credit 
WHERE card_id= (select distinct card_id 
       from Raw where 
       id = (select max(b.id) from Raw as b))"); 

if($resultSet->num_rows != 0){ 

while($rows = $resultSet->fetch_assoc()) 
    { 
     $card_id = $rows['value']; 

     echo "<p>Saldo: $card_id"; 
     $_SESSION['card_id']=$card_id; 
?> 
1

您可以使用$_SESSION整個應用程序。 要存儲會話你永遠需要啓動session_start();

如果我們看一下你的例子:

<?php 
session_start(); 
$resultSet = $mysqli->query ("SELECT value FROM card_credit 
       WHERE card_id= (select distinct card_id 
       from Raw where 
       id = (select max(b.id) from Raw as b))"); 

if($resultSet->num_rows != 0){ 

while($rows = $resultSet->fetch_assoc()) 
    { 
     $card_id = $rows['value']; 
     $_SESSION['card_id'] = $card_id; //Set session variable 
     echo "<p>Saldo: $card_id"; 
    } 

現在我們可以使用這個會話變量另一個頁面上,例如test.php的:

<?php 
session_start(); 
echo $_SESSION['card_id']; //Echo's the id 
0

嘗試使用此:

<?php 
    // Start the session 
    session_start(); 

    $resultSet = $mysqli->query ("SELECT value FROM card_credit WHERE card_id= (select distinct card_id from Raw where id = (select max(b.id) from Raw as b))"); 

    if($resultSet->num_rows != 0){ 
     $card_id = $rows['value']; 
     // Set session variables 
     $_SESSION["card_id"] = $card_id; 
     //echo "Session variables are set."; 
     echo "<p>Saldo: $card_id"; 
    } 
?>