What am I doing wrong? $rs['count'] is set to "468732" in a function that is returns an array. $max_results = 25; $top = $rs['count']; echo ($top + 1)."<br />"; $numpages = $top / 25; echo $top. " / ".$max_results." = ".$numpages; exit; PHP: Output: 1 469190 / 25 = 0 I do not understand what is wrong.
You're script works when I take out the $top = $rs['count']; I think I had a similar problem in a script I wrote in perl. I used sprintf. I think it might have to do with the type of variable you are trying to pass. This works for me. check out the script here. www.wineryfinder.net/dude.php $max_results = 25; $top = 5; echo ($top + 1)."<br />"; $numpages = $top / 25; echo $top. " / ".$max_results." = ".$numpages; Code (markup):
Count is an array. The array assigns it's as an string even though I type cast it as an int. Still shouldn't php change it to int when doing math operations? Instead for some reason it is assigned the var to be a zero instead of the number. Which is wierd, because there is no white spaces in the string and should be read by php like a integer. Maybe it is just something wrong with my install of php?
Do this $top = intval($rs['count']); PHP: This will process the array as an integer if it is not already. To check if it's an integer do this. print_r($rs); PHP: This will print all keys, indexes and values of the array $rs;
$top = intval($rs['count']); if($top > 0){ $max_results = 25; echo ($top + 1)."<br />"; $numpages = $top / 25; echo $top. " / ".$max_results." = ".$numpages; exit; } PHP: Peace,
I found the error. For some reason the count var had xml stuff in it and firefox wasn't showing it. I feel stupid. I changed up the rss scrape routine to do the [1] instead of [0] and now it is grabbing only the ints.