1
這是我的輸出到我的分號的文本文件數據庫PHP我while語句是關閉的增量不工作
MSG2;This is the first test;William;
MSG2;This is the second test;William;
MSG2;This is the third test;William;
MSG1;This is the third test;William;
我正在拍攝的是這個...
MSG 1;This is the first test;William;
MSG 2;This is the second test;William;
MSG 3;This is the third test;William;
MSG 4;This is the third test;William;
這裏我的變量
<?php
$x = 1;
while($x < 1) {
$x++;
}
if(isset($_POST['field1']) && isset($_POST['field2'])) {
$data = 'MSG' . $x . ';' . $_POST['field1'] . ';' . $_POST['field2'] . ';' ."\n";
$ret = file_put_contents('data.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
echo "$ret bytes written to file";
}
}
else {
die('no post data to process');
}
?>
我想了解num ++的概念。我該如何解決我的問題?謝謝。
這就是所謂的增量運營商,它提出了使用它的電流後的$一個* NUM值值* – e4c5
'$ x = 1; while($ x <1){ $ x ++; }由於'$ x'開始時爲'1',並且您的循環在'$ x <1'時運行,所以永遠不會運行 –
您可能會發現'for'循環在這裏更有用:http:// php.net/manual/en/control-structures.for.php – Eraph