cycle through this in sections
Posted: Sun Feb 12, 2006 7:34 pm
I have the code for my script below, what it does is cycles through a lot of entries in the DB and Updates the data fro them, the problem is I need to have it do like 5 at a time then do 5 more then 5 more and so on instead of doing them all at the same time which makes the script timeout
Code: Select all
<html>
<body>
<?php
include "globals.php";
include "db.php";
$query = "SELECT intMSId FROM users WHERE trainnumber='$trainnumber' AND intPriority > 0";
$res = mysql_query($query) or die("Error: " . mysql_error());
$count = 0;
while ($row = mysql_fetch_array($res)) {
$MSid = $row['intMSId'];
$html = file_get_contents("http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=$MSid");
preg_match("/<span class=\"nametext\">(.*)<\/span>/", $html, $msname);
preg_match("/<td class=\"text\" width=\"193\" bgcolor=\"#ffffff\" height=\"75\" align=\"left\">\"(.*)\"<br>/", $html, $msdata);
preg_match("/has <span class=\"redbtext\">(\d+)<\/span> friends/", $html, $msfc);
preg_match("/(\d+) years old/", $html, $msyo);
preg_match("/ctl00_Main_ctl00_.*<img src=\"(.*)\" border=\"0\" \/><\/a>/", $html, $msimg);
$msdata[1] = mysql_escape_string($msdata[1]);
$msname[1] = mysql_escape_string($msname[1]);
if ($msname[1] != "")
{
$query = "update users set txtMSName='"
. addslashes($msname[1]) . "', intMSAge='"
. addslashes($msyo[1]) . "', intMSFriends='"
. addslashes($msfc[1]) . "', txtMSText='"
. addslashes($msdata[1]) . "', txtMSImg='"
. addslashes($msimg[1]) . "' WHERE intMSId=$MSid";
mysql_query($query) or die("Error: " . mysql_error());
$count++;
} else
{
$error = "User doesnt exists ($MSid)";
print "$error<br>";
}
}
echo "<p>$count users with priority (> 0) have been updated.</p>";
?>
</body>
</html>