伙计们,我正在尝试更新有 6 万行的表,这是我的代码:
忽略代码的逻辑,看看它有多少查询和循环。我,计划对主查询设置一个限制,但我希望它是 SQL 的最大限制,这样我可以节省时间。有什么想法吗?
$query=mysql_query("SELECT DISTINCT(nid) FROM `comment` LIMIT ");
//mysql_query("UPDATE comment set thread = '00/' WHERE pid = 0 and uid = 333333");
while($result=mysql_fetch_array($query))
{
$query2=mysql_query("SELECT cid,pid,thread FROM comment WHERE nid = ".$result['nid']." ORDER by created");
while($result2=mysql_fetch_array($query2)){
$nodethread = 0;
if($result2['pid'] == 0)
$thread = int2vancode($nodethread) . "/";
else{
$parent = (string) rtrim((string) $result2['thread'], '/');
$parent=explode('.',$parent);
echo $parent." this is parent</br>";
$max=max($parent);
if($max == '')
{
$thread = $result['thread'].'.'.int2vancode(0) .'/';
}
else
{
//$parts = explode('.', $max);
$parent_depth = count($parent);
echo "parent".$parent_depth;
$last = $parent[$parent_depth];
$thread = $result2['thread'] .'.'. int2vancode(vancode2int($last) + 1) .'/';
}
}
mysql_query("UPDATE comment set thread = '$thread' where cid = ".$result2['cid']."");
}
}
所以总结一下我的代码,我首先有一个:
while loop for my first query
then i have another while loop inside for my second query
and lastly i have an update inside.