【问题标题】:How to store a html div into a php session?如何将 html div 存储到 php 会话中?
【发布时间】:2015-08-14 13:11:50
【问题描述】:

我需要帮助将我的 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>

这是我的 email-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'];



?>

【问题讨论】:

  • 请分享您的代码。到目前为止你尝试过什么?

标签: javascript php ajax html session


【解决方案1】:

尝试使用以下代码:

            $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;

【讨论】:

    【解决方案2】:

    您可以在会话变量中获取一个日期,然后在下一页使用该日期,您可以获取记录并发送邮件。

    【讨论】:

      【解决方案3】:

      我不明白您为什么要将div 存储到session

      您只需要做的是,从您的数据库中获取一些结果,在页面上显示它们,如果有人点击发送电子邮件按钮,创建 div 并填充数据,然后发送。简单的伴侣。

      【讨论】:

        猜你喜欢
        • 2015-09-13
        • 2011-07-31
        • 2013-08-06
        • 2013-09-01
        • 1970-01-01
        • 2016-07-29
        • 1970-01-01
        • 2010-12-16
        • 2020-04-23
        相关资源
        最近更新 更多