0

I'm doing two buttons Next and previous i have this line of code in the php file and the function defined in another php fixer, the one that has to do the function is to go to the taula where I am and select the next product. The problem is that the button does nothing.

I tried to put the ide in another way but it does not do anything when I hit the button

public static function botoSeguent(){
    if(isset($_POST['Seguent'])){
    $Ordre=$_POST['Ordre']+1;
    $sql= "SELECT * FROM" .self::$tablename. " WHERE Ordre='$Ordre";
    $query = Executor::doit($sql);
    }
}

The button doesn't do anything.

This is the line I used in PHP file:

<button class="btn btn-primary" type="button" id="botoSeguent()">&nbsp;<i class="fa fa-search"></i>&nbsp;Següent</button>
Cristiano Soares
  • 619
  • 1
  • 9
  • 20
Joel Valor
  • 11
  • 2
  • This is the line I used in document php – Joel Valor Feb 11 '19 at 10:41
  • If that's a PHP function you're attempting to call in HTML - [it won't work](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) (not that it makes sense attempting to call it in an `id` attribute anyway). – CD001 Feb 11 '19 at 10:51
  • 2
    Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – CD001 Feb 11 '19 at 10:51
  • I'm doing everything in php, because I canvio the id by link or why? – Joel Valor Feb 11 '19 at 10:57
  • 1
    PHP runs on the server, not the client (unlike JavaScript) so you **can't** call a PHP function from within HTML. And putting a function call on the `id` doesn't make sense because that's not an event, it's just an attribute - it's not triggered by click or anything. You probably need dynamic output created by JavaScript based on the response from an Ajax call to the server, triggered by the *click* event... which is essentially a full blown Ajax tutorial and therefore too broad in scope for Stack Overflow's simple QA format. – CD001 Feb 11 '19 at 11:05

1 Answers1

0

You need to call the php function via javascript. There is two part one is server site script which is PHP code and another one is client side script which is HTML, Javascript etc. Here is the example

This is client side script:

    <button class="btn btn-primary" type="button" onclick="botoSeguent();">&nbsp;<i class="fa fa-search"></i>&nbsp;Següent</button>

<script>
function botoSeguent() {
    $.ajax({
        url: 'http://xxxxx.com/botoSeguent',
        type: 'POST',
        success: function (data) {

        }
    });
}
</script>

This is your server side script

public static function botoSeguent(){
    if(isset($_POST['Seguent'])){
       $Ordre=$_POST['Ordre']+1;
       $sql= "SELECT * FROM" .self::$tablename. " WHERE Ordre='$Ordre";
       $query = Executor::doit($sql);
    }
}

Client side java script ajax call the server side php function when you click the button. Hope it will answer your question.

Omar Sohel
  • 164
  • 4