如何从一段时间开始使用变量,但在一段时间之外使用


How to use variable from a while, but outside the while?

我有这个:

$nome='x.png';
if(file_exists('../../images/produtos/'.$nome)){
       $i = 1;
       while(file_exists('../../images/produtos/'.$i."_".$nome))
    {
       $i++;
    }
        $nome = $i."_".$nome;
}

然后我需要将变量$nome放入mysql_query中,就像这个一样

mysql_query("INSERT INTO produtos (nome) VALUES ('$nome)");

但它不显示"已编辑"的变量。

正如@PhpXp对以下Stackoverflow帖子的回答所指出的,您可以尝试在while循环之前定义变量。见下文:

$report = "";
while ($row = mysql_fetch_array($result)) {
    $report += "a"."b".$row["prevDOCid"]+1;
}
echo $report;