How to create loop query sql ?
I want to retrieve emails in a text file and insert these emails in SQL queries to deal with.
Code:
Here is my case:
$ fp = fopen ( "$ file", "r") / / We open the file
while (! feof ($ fp))
(
$ line = fgets ($ fp, 255) / / It gets the lines of the file (emails ..)
mysql_query ( "UPDATE members SET email = NULL WHERE email = '$ line'");
echo $ line. '<br />';
)
Problem is that above query does not work. emails are not deleted from database.
Can you help me ?
Thanks
Re: How to create loop query sql ?
fgets function returns an entire line of a file, up to meet a newline (character \ n). The problem is precisely that it returns the \ n with! So in your comparison between the field of comics and the variable $ line, and you are with a character too
Re: How to create loop query sql ?
Transact-SQL statement or statement grouping as defined with a statement block. To define a statement block, use the control-of-flow keywords BEGIN and END.
BREAK
Causes an exit from the innermost WHILE loop. Any statements that appear after the END keyword, marking the end of the loop, are executed.
CONTINUE
Causes the WHILE loop to restart, ignoring any statements after the CONTINUE keyword.
Example
Code:
DECLARE Employee_Cursor CURSOR FOR
SELECT EmployeeID, Title
FROM AdventureWorks.HumanResources.Employee
WHERE ManagerID =3;
OPEN Employee_Cursor;
FETCH NEXT FROM Employee_Cursor;
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM Employee_Cursor;
END;
CLOSE Employee_Cursor;
DEALLOCATE Employee_Cursor;
GO