Huijari Posted January 23, 2010 Share Posted January 23, 2010 Ok, so I previously posted a problem and got fix on it. Unfortunately I found that my script doesn't work like I want it to do. Here's the code: if(!file_exists($file)){ $fh=fopen($file, 'w'); if ($iii>0) { fwrite($fh,"&s" .$iii. "x=$x_coord2,&s" .$iii. "y=$y_coord'w'\n"); $iii -1; } else { fclose($fh); echo "<br/>"; echo "ok<br/><br/>"; } Ok, so now $iii is number 3 for example. And if its greater than 0, it will write to file. But it should do fwrite 3 times, always when $iii -1; It should do this 3 times: fwrite($fh,"&s" .$iii. "x=$x_coord2,&s" .$iii. "y=$y_coord'w'\n"); And all 3 would be same but $iii in then would be 3,2,1 So how to do it so, it always return to do fwrite if $iii is greater than 0? Link to comment https://forums.phpfreaks.com/topic/189563-return-fwrite-3-times/ Share on other sites More sharing options...
PHP Monkeh Posted January 23, 2010 Share Posted January 23, 2010 Get a loop in there! if(!file_exists($file)) { $fh = fopen($file, 'w'); for($i = 3; $i > 0; $i--) { fwrite($fh,"&s" .$i. "x=$x_coord2,&s" .$i. "y=$y_coord'w'\n"); } fclose($fh); echo "<br/>"; echo "ok<br/><br/>"; } Link to comment https://forums.phpfreaks.com/topic/189563-return-fwrite-3-times/#findComment-1000576 Share on other sites More sharing options...
Huijari Posted January 24, 2010 Author Share Posted January 24, 2010 Thank you so much Monkeh. I am not so good with PHP, I thought it would automatically loop. Thanks a lot Link to comment https://forums.phpfreaks.com/topic/189563-return-fwrite-3-times/#findComment-1000753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.