Forum Moderators: coopster

Message Too Old, No Replies

Setting a max in a "for" statement

         

Jeremy_H

7:36 pm on Nov 6, 2006 (gmt 0)

10+ Year Member



Hello, I would like to set a maximum in a "for" statement.

I'm using data from a MySQL table, with a varying amount of keys.

I would like to have a maximum of three expressions showing, but if there are less than three, say two, I only want to run the function two times.

Right now, I have the following statement, which works fine if there are up to three keys in the table, but right now, it will just keep on running all the way up to the total amount of keys.

for($i=0;$i<count($keys);$i++){...}

Is there a way I can set a max at three?

Thanks

Little_G

8:00 pm on Nov 6, 2006 (gmt 0)

10+ Year Member



Hi,

Have you looked at the LIMIT option in your SELECT query. here [dev.mysql.com]

Andrew

coopster

11:29 pm on Nov 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Good idea, then just use a while loop instead.