LIMIT does not interpret the variables

-4

Does anyone know why the variables are not interpreted?

I'm passing via ajax with data:{"inicio=0&fim=2"} and when I try to return to the query I can not.

$.ajax({
    url: 'php/teste.php',
    type: 'POST',
    data: "inicio=0&fim=2",
    beforeSend: '',
    error: '',
    success: function(leitura){
    alert(leitura);             
    }
});

test.php

$inicio = $_POST['inicio'];
$fim    = $_POST['fim']; 

$usuarios = mysql_query("SELECT * FROM usuario LIMIT $inicio,$fim") or die(mysql_error());

I have already used ( int ) but it returns 0 ;

Mysql 5.7

    
asked by anonymous 28.05.2018 / 17:39

1 answer

0

Hello, you are reading from your Database, so use the "GET" method. See a little about http requests:

HTTP Requests

You should be trying to do this:

<script>                                         
   $(document).ready(function(){                                        
    $.ajax({
            type: 'GET',
            url: 'www.seusite.com/teste.php?inicio=0&fim=2',
            success: function(data)
            {
              $("#IdDeUmaDiv").append(data);
            }
             });                                                          
         });                                                        
</script>

<div id="IdDeUmaDiv"></div>

You can do this in an easier way! Use jquery's load! Create a simple page for results and just load the div when you need it! Here's how it's simple:

<a onclick="$('#IdDeUmaDiv').load('url');">Buscar</a>

You can pass the parameters through the url and pick up the file using $ _GET ["parameter_name"];

Your SQL is wrong! See a little how it works! Do not use "Limit" for this Use BETWEEN! Here's how it works:

BETEWEEN

    
28.05.2018 / 19:16