Greenhalgh David wrote: > A quick question about a while loop. > > I have a simple code that searches database for all entries and puts > one of the fields into a select box on the output page. However, due > to a mistake in my untaint routine (which I've fixed) if a visitor > entered their name in Japanese characters, the entry into the data > base is blank. That means that my simple while loop: > > while ($name=$sth->fetchrow_array()) {
You have a subtle bug here. It should be: while (($name)=$sth->fetchrow_array()) { This forces the assignment to be in list context. That way, the while() condtion will be true if fetchrow_array returned any values, or false if it returned an empty list. That would make the blank value not terminate your loop. > print "<option>$name</option>"; > } > > stops when it hits the blank name. I can also select the ID number.. > > while (($name, $ID)=$sth->fetchrow_array()) { > print ."<option>$name</option>"; > } > > Since this is deployed code, I would like to know if this will work > before I try it. Will the loop stop when $name is blank, or will it > keep running because $ID is NOT blank and stop only when both are > blank? The loop will keep running as long as fetchrow_array returns a row, even if both columns are blank. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]