RE: [PHP] Feelin' dumb...

2002-05-18 Thread Jason Soza

Thanks everyone for your help on this, this is the final code:

if ($num_pages = 2) {
for ($i=0, $p=1; $i$num_pages; $i++, $p++) {
$j = ($i==0) ? $i : $j+20;
printf(| a href=\test.php?type=allpage=%s\Page 
%s/a | ,
$j, $p);
}
}

Because of the way MySQL uses LIMIT, I found that using LIMIT 1, 20 and
LIMIT 21, 20 leaves out the 1st and 20th records. So I had to change $i to 0
to get them back. However, this left me with Page 0 | Page 1 - not cool,
so I added $p into the loop, but started it at 1 so I'd have a variable to
use for correct page numbers.

Oh and I had to change $i=$num_pages to just $i$num_pages because with
$i=0, I was getting an extra iteration. What a learning experience!

Thanks again,

Jason Soza

-Original Message-
From: Richard Baskett [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 8:47 PM
To: Jason Soza; PHP General
Subject: Re: [PHP] Feelin' dumb...


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.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Feelin' dumb...

2002-05-17 Thread Jule

try,

for ($i=1; $i=$num_pages; $i = $i + 20) {
}


or try,

$i = 1;
while ($i=$num_pages) {
//text here
$i = $i + 20;
}

I got those little problems too all the time..
and the boards/lists always help.
Jule

On Friday 17 May 2002 23:19, you 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

--

|\/\__/\/|
|   Jule Slootbeek   |
|   [EMAIL PROTECTED]|
|   http://blindtheory.cjb.net   |
|   __   |
|/\/  \/\|

---

-- 
|\/\__/\/|
|   Jule Slootbeek   |
|   [EMAIL PROTECTED]|
|   http://blindtheory.cjb.net   |
|   __   |
|/\/  \/\|

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Feelin' dumb...

2002-05-17 Thread Richard Baskett

Hmm... Wouldn¹t you just do this?:

for ($i=1; $i=$num_pages; $i+20) {
  // print stuff here
}

Rick

The vision must be followed by the venture. It is not enough to stare up
the steps - we must step up the stairs. - Vance Havner

 From: Jason Soza [EMAIL PROTECTED]
 Date: Fri, 17 May 2002 19:19:28 -0800
 To: [EMAIL PROTECTED]
 Subject: [PHP] Feelin' dumb...
 
 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




Re: [PHP] Feelin' dumb...

2002-05-17 Thread Jule

would that work?

isn't $i++; abbr. for $i = $i + 1;

so now the $i + 20; doens't declare anything.

just like $i += $b; is abbr. $i = $i + $b;

Jule.


On Friday 17 May 2002 23:14, you wrote:
 Hmm... Wouldn¹t you just do this?:

 for ($i=1; $i=$num_pages; $i+20) {
   // print stuff here
 }

 Rick

 The vision must be followed by the venture. It is not enough to stare up
 the steps - we must step up the stairs. - Vance Havner

  From: Jason Soza [EMAIL PROTECTED]
  Date: Fri, 17 May 2002 19:19:28 -0800
  To: [EMAIL PROTECTED]
  Subject: [PHP] Feelin' dumb...
 
  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

-- 
|\/\__/\/|
|   Jule Slootbeek   |
|   [EMAIL PROTECTED]|
|   http://blindtheory.cjb.net   |
|   __   |
|/\/  \/\|

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Feelin' dumb...

2002-05-17 Thread Jason Soza

Well, I tried that but the page doesn't finish loading... I.e. a script that
normally doesn't take more than a second to load just sits there. With $i++,
everything's fine - with $i+20, the browser says it's loading, but all I
have is a white screen for about 30 seconds... Then it times out.

-Original Message-
From: Richard Baskett [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 7:15 PM
To: Jason Soza; PHP General
Subject: Re: [PHP] Feelin' dumb...


Hmm... Wouldn¹t you just do this?:

for ($i=1; $i=$num_pages; $i+20) {
  // print stuff here
}

Rick

The vision must be followed by the venture. It is not enough to stare up
the steps - we must step up the stairs. - Vance Havner

 From: Jason Soza [EMAIL PROTECTED]
 Date: Fri, 17 May 2002 19:19:28 -0800
 To: [EMAIL PROTECTED]
 Subject: [PHP] Feelin' dumb...

 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




RE: [PHP] Feelin' dumb...

2002-05-17 Thread Craig Vincent

 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!

Well this is a bit of a detour from the other suggestions however since you
haven't gotten a successful solution yet how about

for ($i=1; $i=$num_pages; $i++) {
$number = ($i * 20) + 1;
// print stuff here
}

The results would be $number = 21 on first run, then 41, then 61 etc (which
I believe is what you are looking for).  Note the parenthesis in the $number
line are not needed however I typically code with them as it makes it easier
to understand the code with less though =)

Sincerely,

Craig Vincent



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Feelin' dumb...

2002-05-17 Thread Richard Baskett

I apologize :)  yes you need to do this:

for ($i=1; $i=$num_pages; $i=$i+20) {
  echo $i - is ibr /;
}

Make sure $num_pages is set though.. If not it wont work you'll just get a
blank white page.  Yes I did some testing *hehe*  It worked beautifully when
$num_pages is set though..

Rick

The human mind is not capable of grasping the Universe. We are like a
little child entering a huge library. The walls are covered to the ceilings
with books in many different tongues. The child knows that someone must have
written these books. It does not know who or how. It does not understand the
languages in which they are written. But the child notes a definite plan in
the arrangement of the books---a mysterious order which it does not
comprehend, but only dimly suspects. - Albert Einstein

 From: Jule [EMAIL PROTECTED]
 Date: Fri, 17 May 2002 23:23:25 -0400
 To: Richard Baskett [EMAIL PROTECTED], [EMAIL PROTECTED]
 Subject: Re: [PHP] Feelin' dumb...
 
 for ($i=1; $i=$num_pages; $i+20) {
   // print stuff here
 }


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Feelin' dumb...

2002-05-17 Thread Tom Rogers

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




RE: [PHP] Feelin' dumb...

2002-05-17 Thread Jason Soza

Thanks Craig, that worked!

I wonder why the other suggestions weren't working. They seemed logical
enough, I even tried variations of your suggestion, first I tried:

for ($i=1; $i=$num_pages; $number = $i + 20) {}

That wasn't working, still was getting the 30 second timeout. Then I tried:

for ($i=1; $i=$num_pages;) { $number = $i + 20; }

Since the manual says any of the expressions can be left blank. That still
executed beyond the 30 seconds and timed out.

Anyways, your suggestion is MUCH faster! Thanks for everyone's help -

Jason

-Original Message-
From: Craig Vincent [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 7:36 PM
To: Jason Soza; [EMAIL PROTECTED]
Subject: RE: [PHP] Feelin' dumb...


 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!

Well this is a bit of a detour from the other suggestions however since you
haven't gotten a successful solution yet how about

for ($i=1; $i=$num_pages; $i++) {
$number = ($i * 20) + 1;
// print stuff here
}

The results would be $number = 21 on first run, then 41, then 61 etc (which
I believe is what you are looking for).  Note the parenthesis in the $number
line are not needed however I typically code with them as it makes it easier
to understand the code with less though =)

Sincerely,

Craig Vincent



--
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




RE: [PHP] Feelin' dumb...

2002-05-17 Thread Craig Vincent

 I wonder why the other suggestions weren't working. They seemed logical
 enough, I even tried variations of your suggestion, first I tried:

 for ($i=1; $i=$num_pages; $number = $i + 20) {}
 for ($i=1; $i=$num_pages;) { $number = $i + 20; }

The problem with these two statements was that the loop would be indefinate.
Without the third option $i is never incremented (unless you manually
increment it from within the loop).  So with your examples $i would always
be 1 and would therefore always be = $num_pages unless $num_pages was zero
or negative.

Sincerely,

Craig Vincent



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Feelin' dumb...

2002-05-17 Thread Jason Soza

Makes sense. Thanks!

Now... I have this little problem:
if ($num_pages = 2) {
for ($i=1; $i=$num_pages; $i++) {
$number = ($i * 20) + 1;
$page = $i+1;
printf(| a href=\test.php?page=%s\Page %s/a | , $number, $page);
}
}

I want $page to be $i + 1, but when I do $page = $i+1;, $i somehow gets
evaluated into the for() loop and an additional iteration is completed. So
basically if I do it this way, I get I'll get 1, 21, 41, when really only 1
and 21 are valid. If I put in $page = $i++; it works correctly, but $i is 1
when I want it to be two. If I take out $page = and put in $i where $page is
in the printf() statement, I get the extra iteration again. Any ideas?

-Original Message-
From: Craig Vincent [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 7:56 PM
To: Jason Soza; [EMAIL PROTECTED]
Subject: RE: [PHP] Feelin' dumb...


 I wonder why the other suggestions weren't working. They seemed logical
 enough, I even tried variations of your suggestion, first I tried:

 for ($i=1; $i=$num_pages; $number = $i + 20) {}
 for ($i=1; $i=$num_pages;) { $number = $i + 20; }

The problem with these two statements was that the loop would be indefinate.
Without the third option $i is never incremented (unless you manually
increment it from within the loop).  So with your examples $i would always
be 1 and would therefore always be = $num_pages unless $num_pages was zero
or negative.

Sincerely,

Craig Vincent



--
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




Re: [PHP] Feelin' dumb...

2002-05-17 Thread Richard Baskett

What do you want the output to look like?  I did this:

$num_pages =120;

if ($num_pages = 2) {
for ($i=1; $i=$num_pages; $i+=20) {
 $page = $i+1;
printf(| a href=\test.php?page=%s\Page %s/a | , $number, $page);
}
}

And got this:

| Page 2 | | Page 22 | | Page 42 | | Page 62 | | Page 82 | | Page 102 |

Rick

If a man is called to be a streetsweeper, he should sweep streets even as
Michelangelo painted, or Beethoven composed music, or Shakespeare composed
poetry. He should sweep streets so well that all the hosts of heaven and
earth will pause to say, Here lived a great streetsweeper who did his job
well. - Dr. Martin Luther King, Jr.

 From: Jason Soza [EMAIL PROTECTED]
 Date: Fri, 17 May 2002 20:09:55 -0800
 To: [EMAIL PROTECTED]
 Subject: RE: [PHP] Feelin' dumb...
 
 Makes sense. Thanks!
 
 Now... I have this little problem:
 if ($num_pages = 2) {
 for ($i=1; $i=$num_pages; $i++) {
 $number = ($i * 20) + 1;
 $page = $i+1;
 printf(| a href=\test.php?page=%s\Page %s/a | , $number, $page);
 }
 }
 
 I want $page to be $i + 1, but when I do $page = $i+1;, $i somehow gets
 evaluated into the for() loop and an additional iteration is completed. So
 basically if I do it this way, I get I'll get 1, 21, 41, when really only 1
 and 21 are valid. If I put in $page = $i++; it works correctly, but $i is 1
 when I want it to be two. If I take out $page = and put in $i where $page is
 in the printf() statement, I get the extra iteration again. Any ideas?
 
 -Original Message-
 From: Craig Vincent [mailto:[EMAIL PROTECTED]]
 Sent: Friday, May 17, 2002 7:56 PM
 To: Jason Soza; [EMAIL PROTECTED]
 Subject: RE: [PHP] Feelin' dumb...
 
 
 I wonder why the other suggestions weren't working. They seemed logical
 enough, I even tried variations of your suggestion, first I tried:
 
 for ($i=1; $i=$num_pages; $number = $i + 20) {}
 for ($i=1; $i=$num_pages;) { $number = $i + 20; }
 
 The problem with these two statements was that the loop would be indefinate.
 Without the third option $i is never incremented (unless you manually
 increment it from within the loop).  So with your examples $i would always
 be 1 and would therefore always be = $num_pages unless $num_pages was zero
 or negative.
 
 Sincerely,
 
 Craig Vincent
 
 
 
 --
 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




RE: [PHP] Feelin' dumb...

2002-05-17 Thread Jason Soza

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




RE: [PHP] Feelin' dumb...

2002-05-17 Thread Jason Soza

I think I figured this out -

Since I only have 2 pages, the first iteration of the loop sets $i greater
than than the number of pages, i.e. $i becomes 21, which is greater than 2,
so the second iteration stops there. Am I seeing this right?

So Craig's way worked because $i was left alone in the for() expressions and
only modified in the statement, therefore on the second iteration, $i was 2
and thus it satisfied the second expression and iterated once more.

I *think* I'm understanding this correctly, though if others see it
differently, please let me know!

-Original Message-
From: Jason Soza [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 8:24 PM
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




Re: [PHP] Feelin' dumb...

2002-05-17 Thread Richard Baskett

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 $Ibr /;
  }
}

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




Re: [PHP] Feelin' dumb...

2002-05-17 Thread Richard Baskett

Easy one!  Hopefully you havent jetted yet :)

Just cut the $number = line to below the printf line and there you have it!

Rick

How wonderful it is that nobody need wait a single moment to improve the
world. - Anne Frank

 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 $Ibr /;
 }
 }
 
 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




RE: [PHP] Feelin' dumb...

2002-05-17 Thread Craig Vincent

 I think I figured this out -

 Since I only have 2 pages, the first iteration of the loop sets $i greater
 than than the number of pages, i.e. $i becomes 21, which is
 greater than 2,
 so the second iteration stops there. Am I seeing this right?

 So Craig's way worked because $i was left alone in the for()
 expressions and
 only modified in the statement, therefore on the second
 iteration, $i was 2
 and thus it satisfied the second expression and iterated once more.

 I *think* I'm understanding this correctly, though if others see it
 differently, please let me know!

Yupthat's what I figured you were doing which was why I saw a problem
with the for loops having $i being incremented by more than one (ex. $i +
20).  In order for that to have worked more effectively you would have
needed to multiple $num_pages by 20 as well before the for loop was called
which was redundantand probably would have caused problems with getting
the proper results from the database depending on how you coded it.

Sincerely,

Craig Vincent



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Feelin' dumb...

2002-05-17 Thread Craig Vincent

 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!

Easy fix =)  Put the $number = ($i * 20) + 1;  at the end of your for loop
so it is the last thing done prior to starting a new loop.

Sincerely,

Craig Vincent



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Feelin' dumb...

2002-05-17 Thread Richard Baskett

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 $Ibr /;
 }
 }
 
 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