Jump to content

[SOLVED] Where do I start (table to log.txt)


jmr3460

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/161446-solved-where-do-i-start-table-to-logtxt/
Share on other sites

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.

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.