Ok Im feeling dumb also now *hehe* What I said about putting the $number
line below the printf line.. Don�t listen to me :) Now that I know what you
want.. I know there is cleaner and better code, but it works :)
if ($num_pages >= 2) {
for ($i=1; $i<=$num_pages; $i++) {
$j = ($i==1) ? $i : $j+20;
echo "| <a href=\"test.php?page=$j\">Page $i</a> | ";
}
}
Rick
Be kind. Everyone you meet is fighting a hard battle - John Watson
> From: "Jason Soza" <[EMAIL PROTECTED]>
> Date: Fri, 17 May 2002 20:44:30 -0800
> To: "Richard Baskett" <[EMAIL PROTECTED]>, "PHP General"
> <[EMAIL PROTECTED]>
> Subject: RE: [PHP] Feelin' dumb...
>
> The 20 is inserted into a MySQL LIMIT query. Page 1 = LIMIT 1,20 to get the
> first 20 records from 1, then Page 2 = LIMIT 21,20 to get the next 20, etc.
>
> I think I see the error here.
>
> if ($num_pages >= 2) {
> for ($i=1; $i<=$num_pages; $i++) {
> $number = ($i * 20) + 1;
> printf("| <a href=\"test.php?page=%s\">Page %s</a> | ", $number,
> $i);
> }
> }
>
> Is ALMOST right... Except that the I need the first iteration to return 1.
> In this case, it returns 21, so the next iteration is 41. Follow me? I need
> 1, 21, not 21, 41. Almost there I think, unfortunately, I need to jet. I'll
> be thinkin' on this one while DJing, definitely!
>
> Thanks again for everyone's help.
>
> -----Original Message-----
> From: Richard Baskett [mailto:[EMAIL PROTECTED]]
> Sent: Friday, May 17, 2002 8:30 PM
> To: Jason Soza; PHP General
> Subject: Re: [PHP] Feelin' dumb...
>
>
> That means $num_pages is equal to 2 so yes the if statement is true and it
> goes onto the the for loop. Now where you are having problems is on the
> second expression in the for loop.. This expression is basically saying "Do
> this for loop while $I is less than or equal to 2. The third expression
> tells the for loop what to do after each iteration which means after the
> first iteration $I is now 21 so it will stop the for loop since it does not
> pass the second expression check in the for loop.. Since $I is not less than
> or equal to 2 since $I is equal to 21 now.
>
> Im not sure where the 20 comes in so if you clarify what it is for then
> maybe we can figure out where it needs to go :) If you just want the loop
> to go through twice then you would set it to:
>
> if ($num_pages >= 2) {
> for ($i=1; $i<=$num_pages; $i++) {
> echo "$I<br />";
> }
> }
>
> Rick
>
> "May the BEST of your past be the WORST of your future" - Unknown
>
>> From: "Jason Soza" <[EMAIL PROTECTED]>
>> Date: Fri, 17 May 2002 20:23:53 -0800
>> To: <[EMAIL PROTECTED]>
>> Subject: RE: [PHP] Feelin' dumb...
>>
>> When I use that, here:
>>
>> if ($num_pages >= 2) {
>> for ($i=1; $i<=$num_pages; $i+=20) {
>> echo "$i";
>> }
>> }
>>
>> I get 1, or whatever I set $i= in the first expression. No other
> iterations.
>> When I use Craig's way, it works - kinda. Based on what I'm using this
> code
>> in, I should get two iterations. I'm counting the number of rows from my
> DB,
>> dividing it by 20, that's the number of pages I have - currently I have 22
>> records, so 2 pages. Here's what I use for that:
>>
>> $sql = mysql_query("SELECT * FROM table");
>> $num_rows = mysql_num_rows($sql);
>> $num_pages = ceil($num_rows/20);
>>
>> So why would I only get 1 iteration? 22/20 = 1.2 rounded up to 2. This
>> satisfies the if ($num_pages >= 2) statement and initiates the loop. $i
>> starts as 1, then should loop once more. If I set $i=0, I echo 0. What
>> gives?
>>
>> I may not be able to answer anymore tonight, have to DJ for 4 hours
>> beginning in about 35 minutes, so I need to get ready for that, but
>> certainly anymore ideas would be great. Thanks!
>>
>> -----Original Message-----
>> From: Tom Rogers [mailto:[EMAIL PROTECTED]]
>> Sent: Friday, May 17, 2002 7:40 PM
>> To: [EMAIL PROTECTED]
>> Subject: Re: [PHP] Feelin' dumb...
>>
>>
>> Hi
>> What you need is
>> for ($i=1; $i<=$num_pages; $i+=20) {
>> // print stuff here
>> }
>>
>> Tom
>>
>> At 01:19 PM 18/05/2002, Jason Soza wrote:
>>> Okay, I'm apologizing right now for this, but I hope it's at least
>>> tolerable. I have this:
>>>
>>> for ($i=1; $i<=$num_pages; $i++) {
>>> // print stuff here
>>> }
>>>
>>> For each loop, I want to add 20 to $i, so after the first iteration, I
> have
>>> 21, then 41, 61, etc. I've tried $i+20, $i + 20, I've tried looking in
> the
>>> manual, but I assume this is some C-type function, and I'm not familiar
>> with
>>> C!
>>>
>>> Any helpers?
>>>
>>> Jason Soza
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php