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
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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.