0

i am parsing a XML data with simplexml_load_file() function and when i display the data using for loop its display correctly from the number i mention to the limit

<?php
for($i=10; $i<=20; $i++){
{
 $offer->name;
}
?>

but when i declare the values through variable it does not work.

<?php
$result_start = $_REQUEST['start'];
$result_limit = $_REQUEST['limit'];


for($i=$result_start; $i<=$result_limit; $i++){
{
 $offer->name;
}
?>

one more strange thing is happening here is that the loop is repeating 2 times more. like if i mention the loop from 10 to 20 so it is showing me the values from 10 to 22.

9
  • what is in the $result_start and $result_limit ? Commented Sep 25, 2012 at 17:04
  • 1
    See what does variables contains. var_dump($result*); Commented Sep 25, 2012 at 17:04
  • What are those request values when you print them out? Commented Sep 25, 2012 at 17:04
  • the request['start'] and request['limit'] contains the number value from start to limit this i am putting it inside the loop Commented Sep 25, 2012 at 17:05
  • please show the result of var_dump($result_start) and var_dump($result_limit) as @CappY said Commented Sep 25, 2012 at 17:06

1 Answer 1

2

It seems to me the problem would most easily be solved by casting the user input to integers:

$result_start = (int) $_REQUEST['start'];
$result_limit = (int) $_REQUEST['limit'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.