Hi, I am trying the following but it is not writing to the file and only writing one line even though there is 20 rows. //Get Results $query = mysql_query("SELECT * FROM planner"); while ($row = mysql_fetch_array($query)) { $yourdata = get_date($row['date']).";".$row['hours'].";".$row['company']."\n"; } //Write to the file $fp = fopen("test.txt", "w"); fwrite($fp, $yourdata); fclose($fp); PHP: Any ideas? Cheers, Adam
Change the line $yourdata = get_date($row['date']).";".$row['hours'].";".$row['company']."\n"; PHP: to $yourdata .= get_date($row['date']).";".$row['hours'].";".$row['company']."\n"; PHP:
Great that works fine thanks, on another note i want to add up all the hours for every row so it gives me a total hours. Could i do this in the code also or not?
If I understand you right then this is the code: //Get Results $query = mysql_query("SELECT * FROM planner"); $yourdata = ''; $total_hours = 0; while ($row = mysql_fetch_array($query)) { $yourdata .= get_date($row['date']).";".$row['hours'].";".$row['company']."\n"; $total_hours += $row['hours']; } //Write to the file $fp = fopen("test.txt", "w"); fwrite($fp, $yourdata); fwrite($fp, 'Total Hours: '.$total_hours); fclose($fp); PHP: