如何停止重新绘制网页

时间:2012-10-18 06:31:52

标签: php mysql submit redraw

我使用php和mysql创建了一个网页,代码工作正常,但问题是我已经包含了很多提交按钮,因此我的网页被重画了很多次。我失去了一些价值,即$ emirate价值和$ area值。我使用变量$选项来存储这些值但是由于页面正在重绘,我没有得到值。请帮帮我。

$data = mysql_query("SELECT * FROM emirate") 
    or die(mysql_error()); 

    $choice="";

    Print "<table border cellpadding=3>"; 
    print"<tr><th><form method=get action=''><select id=EMIRATE size=1 name='EMIRATE' class='comboBoo'>";
    while($info = mysql_fetch_array( $data )) 
    { 
        Print "<option value=". $info['em_name'] .">".$info['em_name']."</option>"; 
    }
    print"</select><input type=submit value=OK></form></th>";
    if(isset($_GET['EMIRATE'])){
        $emirate=$_GET['EMIRATE'];
        $choice.=$emirate;
        $data = mysql_query("SELECT a_name FROM areas where em_id=(select em_id from emirate where em_name=\"".$emirate."\")") 
        or die(mysql_error());
        Print "<th><form method=get action=''><select id='AREAS' name=AREAS size=1 class='comboBoo'><OPTION value=ALL>ALL</option><OPTION value=ALL>ALL</option>";
        while($info = mysql_fetch_array( $data ))
        {
            Print "<option >".$info['a_name']."</option>";
        }
        print"</select><input type=submit value=OK></form></th>";
    }

    $choice.="->";

    if(isset($_GET['AREAS'])){
        $areas=$_GET['AREAS'];
        $choice.=$areas;
        $data = mysql_query("SELECT h_name FROM hypermarket_em where a_id=(select a_id from areas where a_name=\"".$areas."\")")
        or die(mysql_error());
        Print "<th><form method=get action=''><select name=HYPERMARKETS size=1 class='comboBoo'>";
        while($info = mysql_fetch_array( $data ))
        {
            Print "<option>".$info['h_name']."</option>";
        }
        print"</select><input type=submit value=OK></form></th>";
    }   
    Print "</tr></table>";
    Print "<table border cellpadding=3><tr><th>".$choice."</th></tr></table>";

我怎样才能保留它们?

2 个答案:

答案 0 :(得分:0)

您应该使用javascript使用ajax

仅提交您网页的部分内容(表单中的一个或表单的一部分)

jQuery是一个非常流行且易于学习的JavaScript库,它使得这样的ajax调用非常容易。这是tutorial

另一种解决方案:

如果您不想重新加载页面而又不想使用JavaScript,请将目标设置为不同的页面/框架,如(隐藏)iframe。因此,所有表单的页面都会保留,并且提交的表单的输出可以传递到不同的页面(新窗口,框架或iframe)。

如果你不关心任何回报,你可以隐藏它。这是一个非常基本的例子:

<form target="hiddenframe">
     <input type="submit"/>
</form>
<iframe name="hiddenframe" style="display:none"></iframe>

答案 1 :(得分:0)

$choice="";

    Print "<table border cellpadding=3>"; 
    print"<tr><th><form method=get action=''><select id=EMIRATE size=1 name='EMIRATE' class='comboBoo'>";

 print"</select><input type=hidden name='areas_hidden' value=<?php echo $_GET['AREAS'] ?>/>"
 print"</select><input type=hidden name='emerates_hidden' value=<?php echo $_GET['EMIRATE'] ?>/>"
</th>";

使用您的表单提交操作提交这些值。然后您将同时在您的网址上。