jmr3460 Posted June 9, 2009 Share Posted June 9, 2009 I just got a counter going (Thanks Ken) that enters id, browser info, time and ip to a data table. I just have it on 1 page at the moment but I am planning to add to all of my pages with refer as another field. I hope to eventually be able to generate a report if this information. My question is what is the basic query to extract data from the table and write it to a log file? I am just learning I just need enough information to start my quest. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/161446-solved-where-do-i-start-table-to-logtxt/ Share on other sites More sharing options...
fenway Posted June 9, 2009 Share Posted June 9, 2009 I don't understand... you mean to query this table? What output are you expecting? Quote Link to comment https://forums.phpfreaks.com/topic/161446-solved-where-do-i-start-table-to-logtxt/#findComment-852220 Share on other sites More sharing options...
jmr3460 Posted June 9, 2009 Author Share Posted June 9, 2009 I just made a script that reflects the information to a html page. I was hoping to create a script that reflects the data to a text file, or log file if you will. I found some functions at PHP.net and I am going to give it a whirl. I am trying to learn how to do this thing. If I depend on too many people and never try and write my own stuff I will never learn. Quote Link to comment https://forums.phpfreaks.com/topic/161446-solved-where-do-i-start-table-to-logtxt/#findComment-852756 Share on other sites More sharing options...
jmr3460 Posted June 10, 2009 Author Share Posted June 10, 2009 OK I got something. Not exactly what I want yet. What I got is from a couple of scripts that I have stored in my PHP success files folder. I took my SELECT query from my counter and a file write script I got from the PHP.net. I combined and got this. <?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 ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> Well It writes to the file this great, but it only gives me the first string from the array $info['id']. I thought the while loop would go through every row in the Database to the end. I am only getting only the 1st string in the array from the first row only. Do I have my while loop in the right place? Quote Link to comment https://forums.phpfreaks.com/topic/161446-solved-where-do-i-start-table-to-logtxt/#findComment-852791 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.