jmr3460 Posted June 10, 2009 Share Posted June 10, 2009 I am trying to get this script to work. Where have I gone wrong. This file writes the first string of the first row only. What did I do wrong? <?php include("dbin.php"); $table = "home"; mysql_connect($host, $user, $pass); mysql_select_db($database) or die(mysql_error()); $data = mysql_query("SELECT id FROM $table"); $info = mysql_fetch_array($data); $log = $info['id'] . " | " . $info['ip'] . " | " . $info['time'] . " | " . $info['browser']; $filename = 'log.txt'; if (is_writable($filename)) { if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } while (fwrite($handle, $log) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote () to file " . $filename; fclose($handle); } else { echo "The file $filename is not writable"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/161613-solved-data2file/ Share on other sites More sharing options...
taquitosensei Posted June 10, 2009 Share Posted June 10, 2009 try doing a "\r\n" at the end of each line. That's line break for *nix and Windows. Quote Link to comment https://forums.phpfreaks.com/topic/161613-solved-data2file/#findComment-852809 Share on other sites More sharing options...
jmr3460 Posted June 10, 2009 Author Share Posted June 10, 2009 Yea that worked to make a new line on the text file but I still can't get anything but the first row and the first value of the array. Quote Link to comment https://forums.phpfreaks.com/topic/161613-solved-data2file/#findComment-852827 Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 You only write to the file once. I think you want to loop through the array of results: while($info = mysql_fetch_array($data)) { Don't forget the closing curly bracket. Quote Link to comment https://forums.phpfreaks.com/topic/161613-solved-data2file/#findComment-852828 Share on other sites More sharing options...
jmr3460 Posted June 10, 2009 Author Share Posted June 10, 2009 Thanks that got all the rows in the DB. Why is it only pulling out the first value of the array? Quote Link to comment https://forums.phpfreaks.com/topic/161613-solved-data2file/#findComment-852836 Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 You mean it's just pulling the 'id'? You need to SELECT what you want to pull out. Change this line to: $data = mysql_query("SELECT * FROM $table"); Quote Link to comment https://forums.phpfreaks.com/topic/161613-solved-data2file/#findComment-852839 Share on other sites More sharing options...
jmr3460 Posted June 10, 2009 Author Share Posted June 10, 2009 Thank you very very much. It was so simple. Things are coming together very nicely. Thanks again. You have helped me a time or two before. Quote Link to comment https://forums.phpfreaks.com/topic/161613-solved-data2file/#findComment-852877 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.