单击按钮时,重新加载页面/表单以刷新数据

How to reload the page or form in PHP.

The scenario: I have two forms with the same design/gui. I named it main.php and process.php. Both page also have dropdownlist, same items. The items in the dropdownlist are "Net 1" and "Net 2" and under of "Net 1" is "Bldg 1" and for "Net 2" is "Bldg 2". So in the main.php when I click the submit it will proceed to the process.php. Then process.php will display the under item of the item I choose in the dropdownlist in main.php.

My problem is: When the user want to see the under item of "Net 2". I want is, in the page of button_process.php will just reload or refresh the data so that the user will see the items for "Net 2", what should I do?

Code for main.php:

    <form action="process.php" method="post">
 Advertisement Name: <input type="text" name="adName" size="50"><br/><br/>
 Duration: <select id="duration"name="duration">
     <option value="5 s" >5 s</option>
         <option value="10 s" >10 s</option>
    <option value="15 s" >15 s</option>
    <option value="20 s" >20 s</option>
    <option value="30 s" >30 s</option>
    <option value="60 s" >60 s</option>
    </select><br/><br/>
    <b>Period</b>  <br/>
     From: <input type="text" id="datepickerfrom"name="from"> To: <input type="text" id="datepickerto"name="to">

    <span id="span_select">
        <select name="id">
            <option value="" >- select -</option>

            <?php
                include 'connect.php';

                $q = mysql_query("select fldNetname from tblnetwork");

                while ($row1 = mysql_fetch_array($q))
                {
                  echo "<option value='".$row1[fldNetname]."'>".$row1[fldNetname]."</option>";

                }
            ?>
        </select>
    </span>
    <input type="submit" name="pass" value="View Building/s">   
    </form>
Here's my Code for 

process.php: EDIT:

<form action="button_process.php" method="post">
echo "<div><input type='checkbox' class='checkall'> Check all</div>";
    $all = mysql_query("SELECT fldBldgName FROM tblbuildings");
    while ($row = mysql_fetch_array($all))
       {

       echo "<div><input type='checkbox' name='play[]' class='chk_boxes1' value='" . $row['fldBldgName']."'>";
       echo $row['fldBldgName'];"</div>";

       }


<input type="submit" name="pass" value="View Building/s">   
</form>

Code for button_process.php

<?php
include("connect.php");

switch ($_POST['pass']) {
      case 'View':
           //here I want to reload the page.
            break;


      case 'Save':
            echo "Add";
            break;
}

?>
douzi3756
douzi3756 埃文斯,首先我将它传递到下一页只是为了加载下面的项目。其次,我不知道如何在同一页面加载它。
7 年多之前 回复
douye7033
douye7033 你为什么要做一个表单提交只显示一个菜单项?
7 年多之前 回复

2个回答



如果重新加载页面需要用户操作,您将无法使用PHP重新加载页面,在这种情况下,您将 必须使用Javascript。</ p>

如果您想使用PHP重新加载页面,这将在页面加载时和输出任何html代码之前发生,您可以使用:</ p>

  header('Location:'。$ _ SERVER ['REQUEST_URI']); 
</ code> </ pre>

如果要刷新页面 在用户执行了一个动作之后,你需要一个元素上的javascript事件方法(例如按钮上的例子,onclick()),在方法中你可以使用以下代码:</ p>

< pre> window.location.reload();
</ code> </ pre>

如果这还不足以回答您的问题,请提供您想要的更多详细信息 去做。 有一种比你正在做的更好的方法,有更多的细节,我们可以帮助你更多。</ p>
</ div>

展开原文

原文

If reloading the page requires a user action, you will not be able to use PHP to reload the page, in this case, you would have to use Javascript.

If you want to reload a page using PHP, which will happen as the page load and before any html code is outputted, you can use this :

header('Location: '.$_SERVER['REQUEST_URI']);

If you want to refresh the page after the user has executed an action, you will need a javascript event method on an element (for exemple, onclick() on a button), and within the method you can use the following code :

window.location.reload();

If this isn't sufficient to answer your question, please provide more details as to what you want to do. There is a better way to do it than what you are doing, with more details we might be able to help you more.

douyanzan9145
douyanzan9145 你可以帮帮我
7 年多之前 回复
duanjiagu0655
duanjiagu0655 再次编辑...那就是我在main.php..main.php和process.php中的所有html都有相同的代码/ gui。
7 年多之前 回复
dongzuozhu66776
dongzuozhu66776 已编辑我的帖子...希望你能帮助我
7 年多之前 回复
duai8153
duai8153 我没有看到任何HTML代码。
7 年多之前 回复
douqiang3768
douqiang3768 不,这太具体了,关于你的案子的信息太少了。 如果您希望有人帮助您,则需要显示整个HTML代码。
7 年多之前 回复
douhan4812
douhan4812 你可以给我一些示例代码吗?
7 年多之前 回复
du5114
du5114 您将不得不使用Javascript,我建议您阅读有关Javascript的教程,特别是“DOM操作”。
7 年多之前 回复
doucezhu3570
doucezhu3570 实际上这是我的问题。 当用户在下拉列表中更改内容时,如何查看网格中的项目。 网格用于显示它依赖于下拉列表的项目。
7 年多之前 回复

A quick and dirty example of setting expanding menus on different pages. Build the menu items first then use a php script to set the parent menu item to have a active css style and have your css styles give the proper hide/show styles.

HTML

<div class="menu">
    <div class="menuitem <?php echo $Page=="Net 1" ? "active" : "";?>">
        <span>Net 1</span>
        <div class="submenu">
            <div class="submenuitem">
                <span>Bldg 1</span>
            </div>
        </div>
    </div>
    </div> class="menuitem <?php echo $Page=="Net 2" ? "active" : "";?>">
        <span>Net 2</span>
        <div class="submenu">
            <div class="submenuitem">
                <span>Bldg 2</span>
            </div>
        </div>      
    </div>
</div>

CSS

.menuitem .submenu {
    display:none;
}

.menuitem.active .submenu {
    display:block;
}

where $Page is some php variable that holds the name of your menu item or however you want to tell your script which menu item the user is on.

dora0817
dora0817 编辑我的帖子
7 年多之前 回复
donlih2986
donlih2986 嗨...呃...“网2”和“网2”之下来自数据库。
7 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐