2015-08-14 52 views
-1

我需要幫助將我的div存儲到php會話中。如何將html div存儲到php會話中?

<div name = "divResults"> 
(display results from mysql) 
</div> 

什麼,我需要做的恰恰是:

- 通過日期>搜索記錄。
- >結果將顯示在下一頁。
- >將會有一個按鈕發送電子郵件。
- >我的div中的結果將通過電子郵件發送給用戶。

我可以發送電子郵件,但無法發送結果。我已經使用這個

這是我的代碼結果頁面試圖通過日期搜索後:

<div name = "divResults"> 
<?php 

$getquery = mysql_query("SELECT * FROM Records WHERE Date = '".$sdbStart."' AND Records.SerialNumber NOT IN (SELECT SerialNumber FROM ImportData WHERE Date ='".$adbStart."') ORDER BY Date DESC LIMIT $start, $per_page"); 

          $_SESSION['getquery'] = $getquery; 
echo "<table id=wTable>"; 
          echo "<table id=hTable style=width:800px; border=1px;> 
            <tr style=background-color:black;color:yellow;font-size:18px;> 
            <th style=width:25px>ID</th> 
            <th style=width:200px>Username</th> 
            <th style=width:175px>Date</th> 
            <th style=width:225px>Serial Number</th> 
            <th style=width:200px>Location</th> 
            </tr>"; 

          echo "</table>"; 
          echo "<div id ='test' style=width:820px;height:200px;overflow:auto;>"; 
          echo "<table id=dTable width=800px border=1px>"; 

          while($row = mysql_fetch_assoc($getquery)) 
          { 
          $r +=1; 
          echo "<tr style=color:black;background-color:lightgrey;font-size:13px;>"; 
          echo "<td style=width:25px>" . $r . "</td>"; 
          echo "<td style=width:200px>" . $row['Username'] . "</td>"; 
          echo "<td style=width:175px >" . $row['Date'] . "</td>"; 
          echo "<td style=width:225px>" . $row['SerialNumber'] . "</td>"; 
          echo "<td style=width:200px>" . $row['Location'] . "</td>"; 
          echo "</tr>"; 
          } 
          echo "</table>"; 
          echo "</table>"; 
          echo "</div>"; 
?> 
</div> 



<form method = "POST" action = "email-controller.php"> 

     <font style ="color:orange"><b>From :</b></font> 
     <input type = "text" name = "sender" id = "sender" value = "<?php echo $_SESSION['email']; ?>" class = "sender"> 

     <font style ="color:orange"><b>Send to :</b></font> 
     <input type = "text" name = "recipient" id = "recipient"> 

     <input type = "submit" name = "sendEmail" id = "sendEmail" value = "Send"> 
     </form> 

這是我的電子郵件Controller.php這樣的代碼

<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="refresh" content="0;URL=autogeneratereport.php" /> 
</head> 

<?php 
$conn = mysql_connect('localhost', 'un', 'pw'); 

mysql_select_db('db'); 

$sender = $_POST['sender']; 
$recipient = $_POST['recipient']; 
$_SESSION['divData'] = $_POST['divData']; 

session_start(); 
$_SESSION['sender'] = $sender; 
$_SESSION['recipient'] = $recipient; 

$senderQuery = mysql_query("SELECT * FROM Users WHERE Email = '".$sender."'"); 
$senderData = mysql_fetch_array($senderQuery); 
$_SESSION['senderEmail'] = $senderData['Email']; 
$_SESSION['senderFN'] = $senderData['FullName']; 


$recipientQuery = mysql_query("SELECT * FROM Users Where Email = '".$recipient."'"); 
$recipientData = mysql_fetch_array($recipientQuery); 
$_SESSION['recipientEmail'] = $recipientData['Email']; 
$_SESSION['recipientFN'] = $recipientData['FullName']; 


$getquery = $_SESSION['getquery']; 



?> 
+0

請分享您的代碼。你到目前爲止嘗試過什麼? –

回答

0

嘗試使用下面的代碼:

  $html = "<table id=wTable> 
       <table id=hTable style=width:800px; border=1px;> 
           <tr style=background-color:black;color:yellow;font-size:18px;> 
           <th style=width:25px>ID</th> 
           <th style=width:200px>Username</th> 
           <th style=width:175px>Date</th> 
           <th style=width:225px>Serial Number</th> 
           <th style=width:200px>Location</th> 
           </tr> 
       </table> 
         <div id ='test' style=width:820px;height:200px;overflow:auto;> 
         <table id=dTable width=800px border=1px>"; 

         while($row = mysql_fetch_assoc($getquery)) 
         { 
         $r +=1; 
         $html .= "<tr style=color:black;backgroundcolor:lightgrey;font-size:13px;> 
            <td style=width:25px>" . $r . "</td> 
            <td style=width:200px>" . $row['Username'] . "</td> 
            <td style=width:175px >" . $row['Date'] . "</td> 
            <td style=width:225px>" . $row['SerialNumber'] . "</td> 
           <td style=width:200px>" . $row['Location'] . "</td> 
           </tr>"; 
         } 
         $html .= "</table> 
            </table> 
           </div>"; 

      echo $html; 
      $_SESSION['divData'] = $html; 
+0

謝謝!它對我很好:) –

+0

@MarcusWong ..標記我的回答正確 –

0

您可以採取的日期在會話變量中並在下一頁使用此日期可以獲取記錄併發送郵件。

0

我不明白你爲什麼要將div存儲到session

您只需要從數據庫獲取一些結果,在頁面上顯示它們,並且如果有人點擊發送電子郵件按鈕,請創建該數據並填充數據併發送。簡單的伴侶。