-3

I have two buttons in html which are back and next. If i click those buttons a variable gets incremented or decremented. This variable is getting sent to a function.php where there is an sql statement. The statement is:

select * from x where dimension is = value

How do I refresh the page to show my new table out of my query?

That is my php right here:

    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'].'">';




}

maybe my var is not beeing passed probably?

The javascript function is looking like that:

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

I can't really figure out my problem, is my variable which I am generating in the function not passed properly, or is there another problem?

ProgrammerPer
  • 1,125
  • 1
  • 11
  • 26
Arti
  • 1
  • 5

2 Answers2

0

Seems as if you are mixing PHP and javascript here.

Do you have a onClick-function on your button? If you do, and a javascript function is called you can just add window.location.reload(); at the bottom of your javascript function to reload the page.

Tips: Use the edit function on your post and add code related to your problem, then it is easier to get help.

Rikard
  • 191
  • 1
  • 6
0

It is easy to make in JavaScript,

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

And then you just add the function to your button,

<button class="myButton" onclick=myFunction()">Click to reload</button>
codeWithMe
  • 852
  • 12
  • 17