PHP and text data

  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post November 3rd, 2010, 1:53 am

I have a PHP program that I use to track visitors to my website.

It collects, among other things, the page visited, the refferer, the day of visit, the month of visit and the year of visit.

Once the data is colled, it is written to a log text file.

I can view the file by using a text editor but it is not that easy to read.

After some manipulation, the complete log text file is parsed so that I can display each item separately in a table.

Evenually this log text file will have many days, months and years,

What I would like to do is to enter a particular day, month and year and have it display only that portion from the log text file.

Basically then, I need a php script that when I open the log text file, I have a table form where I enter a day, month and year and then submit it to display results for that particular time frame only.

I would appreciate any suggestions
http://www.schembrionics.com
The Ultimate Solutions Center
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post November 3rd, 2010, 1:53 am

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Joined: Mar 12, 2007
  • Posts: 6228
  • Loc: South-Africa
  • Status: Offline

Post November 3rd, 2010, 4:10 am

Why don't you rather store this log in a MySql database ... ?
Let's leave all our *plum* where it is and go live in the jungle ...
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post November 3rd, 2010, 7:27 am

MySQL database is not available
http://www.schembrionics.com
The Ultimate Solutions Center
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 3415
  • Loc: Richland, WA
  • Status: Offline

Post November 3rd, 2010, 7:55 am

Your going to have to load the data into an array and manipulate it. Instead of reading the flat file and put it into an array you can simply just store an array in a serialized format.
#define NULL (::rand() % 2)
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post November 3rd, 2010, 9:06 am

All data in the log text file are basically rows.

Each row is parsed so that each row becomes a series of separate variables, each variable containing the particular data

I know the postion of the day, month and year variables in the row.

I want to be able to enter a particular day, month and year and then display all the rows with that particular date.
http://www.schembrionics.com
The Ultimate Solutions Center
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post November 3rd, 2010, 9:18 am

I'm going to recommend what SpooF suggested. That is the best option for you without any database being available for you.

Here is one way you could attempt this. (Just to give you an idea).
PHP Code: [ Select ]
<?php
$array = array();
$today = date("j/n/Y"); // 3/11/2010
$array[$today]['referrer'] = $referrer;
$array[$today]['other_things'] = $otherThings;
// so on and so forth
 
// saving the contents into the log file
file_put_contents('log.txt', serialize($array));
 
// retrieving the files
$retrieved = unserialize(file_get_contents('log.txt'));
 
echo $retrieved['3/11/2010']['referrer'];
?>
  1. <?php
  2. $array = array();
  3. $today = date("j/n/Y"); // 3/11/2010
  4. $array[$today]['referrer'] = $referrer;
  5. $array[$today]['other_things'] = $otherThings;
  6. // so on and so forth
  7.  
  8. // saving the contents into the log file
  9. file_put_contents('log.txt', serialize($array));
  10.  
  11. // retrieving the files
  12. $retrieved = unserialize(file_get_contents('log.txt'));
  13.  
  14. echo $retrieved['3/11/2010']['referrer'];
  15. ?>
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post November 3rd, 2010, 10:01 am

I have serialzied the data.

Let me explain again.

The data for each visitor is written in the form of a row in the log text file.
For a new visitor, a new row is written.

With some manipulation, each row becomes a number of serialized data elements, element1 is page visited, element2 is refferer, element3 is day, element4 is month, element5 is year, etc.

As you can see I know exactly where the day, month and year are stored in each row

I want to use a POST function so that I can enter a day, month and year and then display the results in an echoed html table.

I must confess, I am a novice PHP programmer and learn much of my stuff by experimentation and advice from people. So if I sound like sometimes I am not talking correctly, please excuse me.

Thanks
http://www.schembrionics.com
The Ultimate Solutions Center
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post November 3rd, 2010, 10:03 am

I should also have added that I want to display all the rows that have the day, month and year in question, not just individual data elements
http://www.schembrionics.com
The Ultimate Solutions Center
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 3415
  • Loc: Richland, WA
  • Status: Offline

Post November 3rd, 2010, 10:26 am

Do you have the code to retrieve the data and your just asking how to display it?
#define NULL (::rand() % 2)
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post November 3rd, 2010, 10:33 am

That's why I suggested having the date as a key... I think that would be easier to search the data by date. But I'm not sure if that's the best way.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post November 3rd, 2010, 11:16 am

Yes, right now I can display all the data by echoing an html table.

My goal is to be able to display only the data for a certain date so I need to know how to select this so when I echo the html table it will only display the rows for the date entered.
http://www.schembrionics.com
The Ultimate Solutions Center
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post November 3rd, 2010, 11:19 am

Anyone else think that the solution could be done in JavaScript?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post November 3rd, 2010, 11:21 am

I would really like to stay with PHP if possible
http://www.schembrionics.com
The Ultimate Solutions Center
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 3415
  • Loc: Richland, WA
  • Status: Offline

Post November 3rd, 2010, 11:26 am

Give me a bit and I'll put something together to show you.
#define NULL (::rand() % 2)
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post November 3rd, 2010, 12:01 pm

The serialized data is displayed with following:

foreach ($log as $logline) {
echo '<tr>';

echo '<td>' . $logline['0'] . '</td>';
echo '<td>' . $logline['1'] . '</td>';
echo '<td>' . $logline['2'] . '</td>';
echo '<td>' . $logline['3'] . '</td>';
echo '<td>' . $logline['4'] . '</td>';
echo '<td>' . $logline['5'] . '</td>';
echo '<td>' . $logline['6'] . '</td>';
echo '<td>' . $logline['7'] . '</td>';
echo '<td>' . $logline['8'] . '</td>';
echo '<td>' . $logline['9'] . '</td>';
echo '<td>' . $logline['10'] . '</td>';
echo '<td>' . $logline['11'] . '</td>';
echo '<td>' . $logline['12'] . '</td>';
echo '<td>' . $logline['13'] . '</td>';
echo '<td>' . $logline['14'] . '</td>';
echo '<td>' . $logline['15'] . '</td>';

echo '</tr>';


}

echo '</table>';

The day is in $logline['3']
The month is in $logline['4']
The year is in $logline['5']

What I would like to do is to somehow POST the day, month and year and then these values would be used to display only the rows that contain the posted day, month and year.
http://www.schembrionics.com
The Ultimate Solutions Center
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post November 3rd, 2010, 12:01 pm

Post Information

  • Total Posts in this topic: 26 posts
  • Users browsing this forum: No registered users and 215 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.