while-loops

Why wont it loop? (PHP and MySQL)

I wrote this code: <?php mysql_connect("localhost", "root", "root") or die("Could not connect: " . mysql_error()); mysql_select_db("internal"); $result = mysql_query("SELECT Title, Message FROM msg"); ?> <?php while ($row = mysql_fetch_array($result, MYSQL_NUM)){ ?> <div> <h3><a href="#"><?php printf("%s", $row[0...

Initiating the same loop with either a while or foreach statement

I have code in php such as the following: while($r = mysql_fetch_array($q)) { // Do some stuff } where $q is a query retrieving a set of group members. However, certain groups have there members saved in memcached and that memcached value is stored in an array as $mem_entry. To run through that, I'd normally do the following foreac...

What's the point of using "while (true) {...}" ?

Why do some people use while(true){} blocks in their code? How does it work? ...

Logical Error in Shell script.Please help (UNIX)

Following is a source code which takes in only 'files',lists the file permissions of a file and prints the output by replacing r=READ,w-WRITE,x-EXECUTABLE. It should also echo "User".But the My problem here is that I have replaced '-' by User but then if the file has a permission of r--x,it also prints "User" @ that point.I know its n...

How do I collect the keys of all true values in an array?

This is slightly modified version of the code in the PHP docs: http://php.net/manual/en/function.next.php <?php $array = array( -1 => true, 0 => false, 1 => true ); while ($bet = current($array)) { if ($bet == true) { echo key($array) . '<br />'; } next($array); } ?> This is as close as I could get t...

Running mysql inside a while loop

I have a while loop of a mysql call but I also am trying to run another mysql query inside of the while loop but it is only doing it once. I can not figure it out. Here is my code: $sql = "SELECT * FROM widget_layout WHERE module_id=".mysql_real_escape_string($id)." AND state='".mysql_real_escape_string($page)."' AND position=".mysql_r...

Launching threads from within while loop, what happens?

Hi, I want to have a while loop that launches a thread on each loop, I am using the following to launch the thread, do I need to have a unique identifier for each thread or becuase it is launching from different loops will it launch ok, or will it overwrite the previous launch as they are using the same identifier? while(x<y){ Runnable...

How to limit items from while loop

This is my while loop from my project : <?php $select = "SELECT * FROM nk_showcase"; $query = $db->rq($select); while ($user = $db->fetch($query)) { ?> <div class="index"> <a href="details.php?id=<?php echo $user['id']; ?>"><img width="200" height="171" alt="<?php echo $user['title']; ?>" src="<?php echo $url; ?>/i...

validating user input

I am almost done with this but there are 2 things that are stumping me in my code. When I query a user for the test score, if the score is not within the 0-100 range, I want to not accept it and then tell them why and ask for another input. I also want to print the letter grade for their average next to their average score. For some reas...

Why does my Perl script loop infinitely?

I developed a script (mainly by visiting multiple solutions and mashing together my favorite) to find and replace words in files. The files are all contained in a directory. For some reason, my script goes into an infinite loop, however it appears that it works. I would appreciate any explanation as to why it won't exit the loop. #!/us...

Exception propagation through nested loops/calls

I'm having trouble understanding how exceptions should propagate. My code (quite similar to the generic code below) executes otherCode() and fails to continue outer when doSomething() throws the exception. I need to loop over parsing a bunch of files, some of which may be formated incorrectly (causing an exception), and then loop over ...

AutoIT: Missing Wend for While

All, Below is the code that I have written in AutoIT. $fileToWrite = FileOpen("C:\output.txt", 1) If FileExists("C:\test.csv") Then $fileHandle= FileOpen("test.csv", 0) If ($fileHandle = -1) Then MsgBox (0, "Error", "Error occured while reading the file") Exit Else While 1 $current...

Foreach Just Echoing First Entry

Apologies if I should know better, but I've been struggling for quite a while with this one. I have a mysql db with 300 rows. It contains 4 columns, "eventid", "player1", "player2", "score". In the game, player1 gives various others (player2) a score out of 100. What I'm trying to do is show the logged in user (player1) a table of the...

While loop break condition

Hi, I want to do some calculations with polygons. So I need the user to input some x and y coordinates. This is performed by the following code: private static boolean isX = true; private static Scanner scanner = new Scanner(System.in); private static double readDouble() { double value = 0; System.out.print("Koordinate " + (is...

Minimize loops in reference to read/write operations

Hi, the last thing I want to minimize today is code that contains while and do-while loops. Here is the original: class Vereinfache3_edit { public static void main(String [] args) { int c1 = Integer.parseInt(args[0]) ; int c2 = Integer.parseInt(args[1]) ; int c3 = Integer.parseInt(args[2]) ; ...