# PHP: using variables in a sql statement

**URL:** <https://forum.kirupa.com/t/php-using-variables-in-a-sql-statement/153291>\
**Category:** programming\
**Created:** [June 30, 2005, 2:05pm UTC](https://forum.kirupa.com/t/php-using-variables-in-a-sql-statement/153291 "2005-06-30T14:05:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![natronp](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@natronp](https://forum.kirupa.com/u/natronp)\
**Post date:** [June 30, 2005, 2:05pm UTC](https://forum.kirupa.com/t/php-using-variables-in-a-sql-statement/153291/1 "2005-06-30T14:05:08Z")

</div>

The end result of what i’m trying to accomplish is a PHP page that’ll return pageable records from a MYSQL db based on users selection in a flash movie. If the user clicks on page one (button) then flash will pass two variables one having the value 1 and a second having the variable 10.  
Then the php will take those variables and build a SQL statement whic returns rows with an index value between 1 and 10, something like this:

```auto
$sql = "SELECT * FROM tablenamegoeshere"; 
$sql .= " WHERE (tablename.index >= $variable1 and <= $variable2";

```

obviously that SQL isn’t nearly correct! Is what i’m trying to do even possible? (before i go down that road) or is there a better solution? I know with coldfusion you can return pageable recordsets. is there a way to do it with PHP?
