LIMIT does not interpret variables

Asked

Viewed 63 times

-4

Does anyone know why 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’m not getting.

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

php test.

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

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

I’ve used the (int) but get back to me 0;

Mysql 5.7

1 answer

0

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

HTTP requests

You must be trying to do it this way:

<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 easier! Use the jquery load! Create a simple page for results and only load into the div when you need it! See how simple:

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

You can pass the parameters by the url and pick up the file using the $_GET["wire name"];

Your SQL is wrong! See how search ranges work! No "Limit" is used for this Use the BETWEEN! See how it works in this Link:

BETEWEEN

  • Perfect!!! Thank you Cristy.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.