My code is here
$query = "SELECT * FROM `table`";
$result = mysql_query($quer开发者_开发百科y);
$arr = array();
while($info = mysql_fetch_array($result)) {
if (!in_array($info['row'], $arr)) {
$arr[] = $info['row'];
}
}
foreach ($arr as $v) {
$pass = "pass";
$query2 = "UPDATE `table` SET pass = '$pass' WHERE row = '$v'";
$result2 = mysql_query($query2);
}
it processes for 2 minutes and nothing happens in db. where could i be wrong ?
Thanks
EDIT: OK i found my mistake. It was about the code that i wrote for generating random pass which i didnt include in my question. thanks everybody thou
One possibility is that you're running out of memory: by storing all of the rows in an array, you'll need a lot of memory before you even get to the update part - in that case, that fully explains why you see no changes; the script never gets to that part.
Another possibility is that your script runs for too long and is stopped. Depending on your server configuration, set_time_limit may be an option in that case.
However, the effect of the script you're showing us here is the exact same as this single query:
UPDATE `table` SET pass = 'pass'
since you have no conditions on the rows in the select, and the only filtering you do is to not store multiple rows with the same value in the row column - but when you get to the update pass, you're identifying each row via the row column, meaning it will update all rows with the same value in the row column. If row values are unique for each row, then there's no need to check if you've already seen the row; if it's not unique, then you need a different criteria when updating.
If you run the update directly, PHP will not need to use a ton of memory and MySQL will not have to search for each individual row during the update; it can just iterate through them all in one go. Unless you're leaving something out here, you'll be much better off just doing that one simple query.
精彩评论