避免多次运行相同的MySQL脚本

时间:2013-01-18 10:01:31

标签: php mysql optimization

我有一个这样的脚本:

$result = array();
$sql = "SELECT DISTINCT Name FROM servers"; //doesn't really matter what this MySQL script is

//storing the same query in two different variables
$result[0] = mysql_query($sql);
$result[1] = $result[0];

for($i = 0; $i < 3; $i++) {

    $result[0] = $result[1];

    while($ret = mysql_fetch_array($result[0]) {
        //run some code
    }

}

不幸的是,上面的代码执行一次,然后下一次迭代不返回任何内容。我做错了什么?

0 个答案:

没有答案
相关问题