Page 1 of 1

Multiple WHILE woes

Posted: Tue Dec 20, 2005 4:16 pm
by blacksnday
heya everyone!

my problem comes from pagintion not correctly
displaying the selected amount at one time.

I know where the problem comes from, but can't
figure out a way to correct it.

The problem comes from my outputPicRate function
being contained within a
while ($row = mysql_fetch_array($result))
while the function also maintains it's own sql code....

Notice the $result is actually coming from the
testpaginate() function

Code: Select all

$query = "SELECT * FROM vf_news_pic_rate WHERE published='1'  ORDER BY id desc ";

//testpaginate() finishes the above query to display the correct links and article            
testpaginate($query, $rows_per_page=3, $pagenumbers=1);

if (!$result) {
  echo "<p>" . $messages['error_no_article_found'] . "</p>";
} else {
 while ($row = mysql_fetch_array($result)) {
    outputPicRate($row['id'], $showall, $show_comment_number=1, $show_rate=1, $show_banner=0, $show_category=1);
  }
}
Now if I didnt use the outputPicRate() within the while,
but instead grab results directly, the pagination works correctly
and will display however many I want it to at once.

Any ideas how to fix this problem?

Posted: Tue Dec 20, 2005 5:02 pm
by AKA Panama Jack
Is the $result variable made a global variable inside the testpaginate function? If not then the mysql_fetch_array is probably failing.

Or return the $result from the testpaginate function with

Code: Select all

return $result;
inside the function.

and then change

Code: Select all

testpaginate($query, $rows_per_page=3, $pagenumbers=1);
to

Code: Select all

$result = testpaginate($query, $rows_per_page=3, $pagenumbers=1);

Posted: Wed Dec 21, 2005 8:46 am
by blacksnday
AKA Panama Jack wrote:Is the $result variable made a global variable inside the testpaginate function? If not then the mysql_fetch_array is probably failing.
I just realized that was indeed the problem.
Now i understand why globals can be tricky in debugging :P

Im actually experimenting right now with different ways to handle
3 normal ideas.

1. Main Function to generate all Article Output
with On/Off switches so that it can be reusuable with different results

2. Sub-Main function that generates initial query and
a way to identify what is being generated from the Main Function.

3. Pagination that finishes the Sub-Main function initial query then within
the Sub-Main function it correctly shows prev/next links based on
what the Main function generates.

And now with the global problem solved... I
can be a happer coder and continue my quest :P
thanks!