1

在这段代码中,我没有找到如何让 table1 带有数据的解决方案。当刷新table1的数据后显示table2消失了!!我怎样才能解决这个问题 ?

         <?php
$menucompare="";
if (isset($_POST["menucompare"]))
{
 $menucompare= $_POST['menucompare'];
 $table1 = '
                        <table id= "Table1" width="100%" border="1" cellspacing="0" cellpadding="0">
                                        <!--SW - You need a tr tag around these headers-->
                                        <th >Weeks</th>
                                        <th ><p></p></th>
                                        <th > More Details</th>


                                        <tr id="tr">

                                                <tr id= "tr " >
                                                   <td  >gggg</td>
                                                   <td >kkkkk</td>
                                                   <td >
                                                                        <form name ="dets" method="POST" action="">
                                                                                <input class = "showt" name ="wnumber" id ="wnumber" type="submit" value= "More Details" />
                                                                                <input type="hidden" name="data" value="wnumber" />

                                                                                   <noscript>
                                                                                <input type="submit" value="Submit"/>
                                                                                   </noscript>
                                                                        </form>
                                                                </td>
                                                </tr>
                                        </tr>
                                </table> ';
}
else if (isset($_POST["data"]))
{
        // put whatever db process you need somwhere in this if statement

         $table1 = '
                        <table id= "Table1" width="100%" border="1" cellspacing="0" cellpadding="0">
                                    <!--SW - You need a tr tag around these headers-->
                                    <th >Weeks</th>
                                    <th ><p></p></th>
                                    <th > More Details</th>


                                    <tr id="tr">

                                            <tr id= "tr " >
                                               <td  >gggg</td>
                                               <td >kkkkk</td>
                                               <td >
                                                                    <form name ="dets" method="POST" action="">
                                                                            <input class = "showt" name ="wnumber" id ="wnumber" type="submit" value= "More Details" />
                                                                            <input type="hidden" name="row_id" value="value of row id" />
                                                                            <input type="hidden" name="data" value="wnumber" />

                                                                               <noscript>
                                                                            <input type="submit" value="Submit"/>
                                                                               </noscript>
                                                                    </form>
                                                            </td>
                                            </tr>
                                    </tr>
                            </table> ';


        $table2 = '
                          <div id="Table2">
                                  <table width="100%" border="1"  cellspacing="0" cellpadding="0">
                                          <tr>
                                                  <th id="wekkNum"> wnumber</th>
                                                  <th>Your place</th>
                                                  <th>Your arr</th>
                                          </tr>

                                          <tr >
                                                  <td>hhhh</td>
                                                  <td>kkkk</td>
                                                  <td>jjjj</td>
                                          </tr>

                                  </table>
                          </div>             
                  ';                   
}
?>

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
        /*Start Functions*/
        function displayVals() {
                var singleValues = $("select option:selected").text();
                $("#hiddenselect").val(singleValues);
                $("p").html("Procent of : &nbsp &nbsp" + singleValues);
        }
        /*End functions*/

        /*Start Ready*/
        $(document).ready(function(){
                $("select").change(function() {
                        displayVals();
                });
        displayVals();

                $("select#menucompare").change(function() {
                        $("#aform").submit();  
                });
    });
        /*End Ready*/
</script>
<form id="aform" method="post">
        <select id="menucompare" name ="menucompare" size="1" onchange="submitaform()">
                <option selected='selected'>Select one</option>
                <option value="value1" <?php    if ($menucompare == "value1") { echo " selected='selected'"; } ?> >Text 1</option>
                <option value="value2" <?php   if ($menucompare == "value2") { echo " selected='selected'"; } ?> >Text 2</option>
                <option value="value3" <?php   if ($menucompare == "value3") { echo " selected='selected'"; } ?> >Text 3</option>
                <option value="value4" <?php    if ($menucompare == "value4") { echo " selected='selected'"; } ?> >Text 4</option>

        </select>
        <input type="hidden" name="hiddenselect" value="<?php echo $menucompare ;  ?>" />      
</form>
<?php
if (isset($table1))
{
        print $table1;
}
if (isset($table2))
{
        print $table2;
}
?>

这是我的全部代码。希望有解决这个问题,我看过所有帖子,但没有类似的问题。

4

2 回答 2

3
/*Start Ready*/
$(document).ready(function(){
    $("select").change(function() { 
        displayVals(); 
    });
    displayVals();

此代码片段中的第二个displayVals();在页面加载后立即触发,我预计这是您的错误的原因,因为在页面加载时尚未选择任何内容。

您的 table2 不会在页面加载或页面刷新(这只是强制页面加载)时显示,因为您有 inline style <div id="Table2" style="display:none;">。与您期望选择选项被保留的类似问题......如果页面刷新,它将被重置为其默认状态,因此没有选定的选项。

于 2012-05-04T17:40:20.920 回答
1

$_POST 值仅在表单提交后的页面上可用。

通过多个页面保持用户输入的一种简单方法是将其作为隐藏的表单字段传递。

因此,您将在“dets”表单中添加一个隐藏的表单字段:

<input type="hidden" name="menucompare" value="'. $menucompare.'" />

此外,您必须去掉第 37 行的“else”

else if (isset($_POST["data"]))

if (isset($_POST["data"]))

尝试这个

于 2012-05-07T19:31:23.167 回答