in_array()/finding page Problem
| From: | Ben G. McCullough | Date: | Thu, 23 Oct 2003 13:52:09 +0000 |
| Subject: | in_array()/finding page Problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-167286@lists.php.net to get a copy of this message | ||
I think I have a flaw of logic in trying to find the correct page in a mutli-page sql result.
Goal - find the correct page [results.php?page=x] when linking from another page.
Current method - loop through a pagination function looking for the matching $id in an array [simplified for illustration]:
[find $maxpages]
$page =1;
$catch=array();
while($page <= $maxpages) {
[set start #]
$result = [get sql results - limit $startnumber, 12]
while($record = mysql_fetch_array($result)) {
extract($record);
$catch[] = $found_id;
}
if(in_array($real_id, $catch, TRUE)) {
$here = $page;
}
$page++;
}
echo "results.php?page=$here";
I never seem to get a "true" return on in_array(), and in testing, I don't seem to be getting a full result set with my look up.
I feel that I am missing something in the logic - or I am approaching this from the wrong direction.
I originally wanted to do the while test as "if in_array is FALSE, continue loop" but I couldn't get that to work at all.
Thank you for any help you can give this newbie.
--