anyone got an idea how to complete the following while loop. I want to set a database column (LT_URL) to a sting ($ltURLarray), but 1st i want to check if it already exist in the db, if it does exist, then I want to test the next sting exist in the db, if it doesnt set LT_URL to $ltURLarray on the i'th attempt. $ltURLarray[0] = 'string0'; $ltURLarray[1] = 'string1'; //....... $ltURLarray[100] = 'string100'; // some how put the follwing in a while loop while i<100: i = 0; URLdata = mysql_query("SELECT LT_URL FROM lt_Users WHERE LT_URL = '$ltURLarray[i]' LIMIT 1")or die(mysql_error()); if (!mysql_num_rows($URLdata)){ $ltURL =$ltURLa[0]; } Code (markup):
Never put MySQL queries in a loop. Better explain what you want to accomplish, there must be a better solution.
However it would look like this. <?php for ($i = 0; $i < 100; $i++) { $URLdata = mysql_query("SELECT LT_URL FROM lt_Users WHERE LT_URL = '".$ltURLarray[$i]."' LIMIT 1") or die(mysql_error()); if (mysql_num_rows($URLdata) === 0) { $ltURL =$ltURLa[$i]; mysql_query("INSERT INTO lt_Users (LT_URL) VALUES('".$ltURL."')"); } } ?> PHP: Not tested, debugged or checked for typos. But it should work.