How to populate HTML dropdown list with values from database

My guess is that you have a problem since you don’t close your select-tag after the loop. Consider separating your database-related code from the markup, it will help you to spot such mistakes easily <?php … // SQL part $sql = mysqli_query($connection, “SELECT username FROM users”); $data = $sql->fetch_all(MYSQLI_ASSOC); // HTML part ?> <tr> <td>Owner</td> … Read more

How to use .nextInt() and hasNextInt() in a while loop

The hasNextInt call blocks until it has enough information to make the decision of “yes/no”. Press Ctrl+Z on Windows (or Ctrl+D on “unix”) to close the standard input stream and trigger an EOF. Alternatively, type in a non-integer and press enter. Console input is normally line-buffered: enter must be pressed (or EOF triggered) and the … Read more

Scanner input validation in while loop

The problem is that nextLine() “Advances this scanner past the current line”. So when you call nextLine() in the while condition, and don’t save the return value, you’ve lost that line of the user’s input. The call to nextLine() on line 3 returns a different line. You can try something like this Scanner scanner=new Scanner(System.in); … Read more

Python – Infinite while loop, break on user input

You can use non-blocking read from stdin: import sys import os import fcntl import time fl = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL) fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, fl | os.O_NONBLOCK) while True: print(“Waiting for user input”) try: stdin = sys.stdin.read() if “\n” in stdin or “\r” in stdin: break except IOError: pass time.sleep(1)

Mixing files and loops

You get the ValueError because your code probably has for line in original: in addition to original.readline(). An easy solution which fixes the problem without making your program slower or consume more memory is changing for line in original: … to while True: line = original.readline() if not line: break …

While loop in batch

set /a countfiles-=%countfiles% This will set countfiles to 0. I think you want to decrease it by 1, so use this instead: set /a countfiles-=1 I’m not sure if the for loop will work, better try something like this: :loop cscript /nologo c:\deletefile.vbs %BACKUPDIR% set /a countfiles-=1 if %countfiles% GTR 21 goto loop