trouble storing data in file
Posted: Tue Aug 15, 2006 10:01 pm
feyd | Please use
... html document with a post of a new comment that would be awesome if i could save it in the same page as it's written but i think i have to save it when the page reloads ...
any help would be greatly appreciated
-tommy
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi, i'm new so be kind....
i'm working on building a site with my friend (he's got the database work) and i have to do the front end... right now i'm just mocking up interactions with the database by storing them in a file and saving them... but i'm not that good at it... i try to load everything that i stored into variables/arrays and resave that at the end of the page
there are basically 3 bits of information 'nc' (number of comments), comments[], and commentRank[].Code: Select all
<?php
$path = "storage.txt";
$lines = file($path);
if(!$lines){
$lines = fopen($path,"x+");
$nc = 0;
}
else{
$nc = (int) $lines[0];
for($i=1;$i<$nc;$i++){
$comments[$i] = $lines[$i*2];
$commentRanks[$i] = (int) $lines[$i*2+1];
}
}
if(isset($_POST['newComment'])){
$comments[$nc] = $_POST['newComment'];
$commentRanks[$nc] = 0;
$nc++;
}
?>Code: Select all
<?php
$handle = fopen($path,'w');
fwrite($handle,$nc."\n");
for($i=0;$i<=$nc;$i++){
fwrite($handle,$comments[$i]."\n");
fwrite($handle,$commentRanks[$i]."\n");
}
fclose($handle);
?>-tommy
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]