PHP: using variables in a sql statement

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:

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