首页 > 解决方案 > 如何在点击 php 时强制刷新?

问题描述

我在 html 中有两个按钮,分别是返回和下一步。如果我单击这些按钮,变量会增加或减少。这个变量被发送到一个有 sql 语句的 function.php。声明是:

select * from x where dimension is = value

如何刷新页面以从我的查询中显示我的新表?

那是我的php就在这里:

    function tbl_showPage($page){


    global $mysqlhost, $mysqluser, $mysqlpwd, $mysqldb;


    $connection=mysqli_connect($mysqlhost, $mysqluser, $mysqlpwd) or die ("Verbindungsversuch fehlgeschlagen");
    mysqli_select_db($connection, $mysqldb) or die("Konnte die Datenbank nicht waehlen.");


    if($page<1)
    {
        $sql_tbl_questions = "SELECT * FROM `questions` where istAktiv='1' && dimension='1'";
    }
    elseif($page>9)
    {
        $sql_tbl_questions = "SELECT * FROM `questions` where istAktiv='1' && dimension='9'";
    }
    else
    {
        $sql_tbl_questions = "SELECT * FROM `questions` where istAktiv='1' && dimension=$page";
    }
    $quest_query = mysqli_query($connection, $sql_tbl_questions) or die("Anfrage nicht erfolgreich");
    $i = 0;

    while ($question = mysqli_fetch_array($quest_query)) {
        $i++;
        echo '<tr>';
        echo '<th>'.$i.'</th>';
        echo '<th>'.$question['question'].'</th>';
        echo '<th class="text-center"><input type="radio" name="'.$question['dimension'].'_question_'.$question['id'].'" value="0" required></th>';
        echo '<th class="text-center"><input type="radio" name="'.$question['dimension'].'_question_'.$question['id'].'" value="2.5"></th>';
        echo '<th class="text-center"><input type="radio" name="'.$question['dimension'].'_question_'.$question['id'].'" value="5"></th>';
        echo '<th class="text-center"><input type="radio" name="'.$question['dimension'].'_question_'.$question['id'].'" value="7.5"></th>';
        echo '<th class="text-center"><input type="radio" name="'.$question['dimension'].'_question_'.$question['id'].'" value="10"></th>';
        echo '</tr>';
        $dimensions = $question['dimension'];
    }
    echo '<tr>';
        echo '<th></th>';
        echo '<th>Kommentar/Ihre Anmerkung</th>';
        echo '<th class="text-center" colspan=5><textarea rows=3 cols=50 name="Kommentar"></textarea></th>';
        echo '</tr>';



    echo '<input type="hidden" name="gesamt" value="'.$i.'">';
    echo '<input type="hidden" name="dimensions" value="'.$dimensions.'">';
    echo '<input type="hidden" name="size" value="'.$_POST['size'].'">';    
    echo '<input type="hidden" name="branche" value="'.$_POST['branche'].'">';




}

也许我的 var 可能没有通过?

javascript函数看起来像这样:

<script type="text/javascript">


var ki = kd = 1;
function increase()
{
    
	ki++;
	

	 $.ajax({
      type: "POST",
      url: 'inc/functions.php',
      data: ({page:ki}),
      success: function(data){
         console.log(data);
      }
    });
	window.location.reload();
	
}

function decrease()
{
	kd--;

	 $.ajax({
      type: "POST",
      url: 'inc/functions.php',
      data: ({page:kd}),
      success: function(data){
         console.log(data);
      }
    });
	window.location.reload();
	
	
}


</script>

我无法真正弄清楚我的问题,是我在函数中生成的变量没有正确传递,还是还有其他问题?

标签: phphtmlajaxjss

解决方案


用 JavaScript 很容易制作,

function myFunction() {
    window.location.reload();
}

然后你只需将功能添加到你的按钮,

<button class="myButton" onclick=myFunction()">Click to reload</button>

推荐阅读