kjtocool Posted December 18, 2007 Share Posted December 18, 2007 This loop is giving me problems, hoping another set of eyes can help. Basically, the variable $pageNumber is refusing to increment, and the variable $comment_start is empty upon echo. Here is the code: <?php // $num_comments is 12 for this run. if ($num_comments > 10) { $comments_remaining = $num_comments; $pages = ""; $pageNumber = 1; $comment_start = 0; while ($comments_remaining > 0) { if ($pageNumber = 1) { $pages .= '<a href="http://www.*****.com/articleIndex.php?tid=' . $article_ID . '&commentStart=' . $comment_start . '">' . $pageNumber . '</a>'; } else { $pages .= ', <a href="http://www.*****.com/articleIndex.php?tid=' . $article_ID . '&commentStart=' . $comment_start . '">' . $pageNumber . '</a>'; } echo "PN: " . $pageNumber . " CR: " . $comments_remaining . " CS: " . $comment_Start; $comments_remaining = $comments_remaining - 10; $pageNumber = $pageNumber + 1; $comment_start = $comment_start + 10; } echo '<table width="70%" border="0" align="center" cellpadding="0" cellspacing="1">'; echo '<tr>'; echo '<td align="right"><span class="style10">Page: ' . $pages . '</span></td>'; echo '</tr>'; echo '</table><br />'; } ?> Here is the output of the echo statement in the while loop: PN: 1 CR: 12 CS: PN: 1 CR: 2 CS: The $pages variable displays properly, though with the incorrect values. Hoping an extra set of eyes can spot what I'm doing wrong. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 18, 2007 Share Posted December 18, 2007 try <?php // $num_comments is 12 for this run. if ($num_comments > 10) { $comments_remaining = $num_comments; $pages = ""; $pageNumber = 1; $comment_start = 0; while ($comments_remaining > 0) { if ($pageNumber = 1) { $pages .= '<a href="http://www.*****.com/articleIndex.php?tid=' . $article_ID . '&commentStart=' . $comment_start . '">' . $pageNumber . '</a>'; } else { $pages .= ', <a href="http://www.*****.com/articleIndex.php?tid=' . $article_ID . '&commentStart=' . $comment_start . '">' . $pageNumber . '</a>'; } echo "PN: " . $pageNumber . " CR: " . $comments_remaining . " CS: " . $comment_Start; $comments_remaining = $comments_remaining - 10; $pageNumber++; $comment_start = $comment_start + 10; } echo '<table width="70%" border="0" align="center" cellpadding="0" cellspacing="1">'; echo '<tr>'; echo '<td align="right"><span class="style10">Page: ' . $pages . '</span></td>'; echo '</tr>'; echo '</table><br />'; } ?> Quote Link to comment Share on other sites More sharing options...
kjtocool Posted December 19, 2007 Author Share Posted December 19, 2007 The only change I noticed was to change: $pageNumber = pageNumber +1; to $pageNumber++; The output remained the same. (I had tried this first, before switching it) Quote Link to comment Share on other sites More sharing options...
rab Posted December 19, 2007 Share Posted December 19, 2007 Change echo "PN: " . $pageNumber . " CR: " . $comments_remaining . " CS: " . $comment_Start; to echo "PN: " . $pageNumber . " CR: " . $comments_remaining . " CS: " . $comment_start; Just a quick look over... Quote Link to comment Share on other sites More sharing options...
kjtocool Posted December 19, 2007 Author Share Posted December 19, 2007 Yep, good eye. That solves one of the issues. Now if I can just figure out what is causing my pageNumber variable not to increment. Output: PN: 1 CR: 13 CS: 0 PN: 1 CR: 3 CS: 10 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 19, 2007 Share Posted December 19, 2007 Got it ! if ($pageNumber = 1) { need if ($pageNumber === 1) { you are resetting the value to 1 on each loop Quote Link to comment Share on other sites More sharing options...
kjtocool Posted December 19, 2007 Author Share Posted December 19, 2007 Can you tell I only learned to write php a month ago? Thanks for the help guys. This forum is a lifesaver. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 19, 2007 Share Posted December 19, 2007 na you ain't I do it all the time a few weeks back I stared at this <?php session_start(); //Login stuff if(valid){ $_SESSION['UserID'] == $row['UserID']; } ?> and couldn't fiugre out why it wasn't working even ppl here missed it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.