Jump to content

Looping dilema which one FOR or while or both


Voodoo Jai

Recommended Posts

I want to read a db tables content to find out how many times an entry occurs, if it is above a certain number then I want to stop the reading and continue on with something else. But If once all the vlaues have been read and are not above the set level then I wan to do something else.

 

the condition is : a count value <11.

if value >11 the stop loop and do somthing else.

 

Do I get the number of rows to read and then use a FOR loop to read all the values until a condition is true. But doesnt this loop have to run through all the values and waste time.

 

Or do I use a WHILE loop that checks for a condtion and if not true then continues to loop until a value is true or until all the values are tested.

 

Read a db value

count value = 0

if count >11

  add to the count value

  read another db value

else

  stop reading the db values and

  do something else

end

 

is this the solution or is there a better way.

 

Many thanks

 

VoodooJai

 

Arrrrrrrrrrrr so if I select all the record with the same value and count them if count >11 do something, else do something else.

Yes I am reading from a MySql db.

 

so would it be

 

SELECT COUNT(value) FROM tableName WHERE value = 123abc;

 

"A little further on"

 

VoodooJai

 

Sorry missed previos reply

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.