PHP and text data

  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post November 3rd, 2010, 12:20 pm

The way you are doing it right now, the only solution that is possible (imo) is to do it in Javascript, unless you are willing to try a different form of putting the content into the log file.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post November 3rd, 2010, 12:20 pm

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

Post November 3rd, 2010, 12:28 pm

Is it possible to do a php search and if it matches the day, month and year, it displays the entire row(s)
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, 12:30 pm

Code: [ Select ]
foreach ($log as $logline) {

if($logline[3] == $day AND $logline[4] = $month AND $logline[5] = $year)
{
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>';
  1. foreach ($log as $logline) {
  2. if($logline[3] == $day AND $logline[4] = $month AND $logline[5] = $year)
  3. {
  4. echo '<tr>';
  5. echo '<td>' . $logline['0'] . '</td>';
  6. echo '<td>' . $logline['1'] . '</td>';
  7. echo '<td>' . $logline['2'] . '</td>';
  8. echo '<td>' . $logline['3'] . '</td>';
  9. echo '<td>' . $logline['4'] . '</td>';
  10. echo '<td>' . $logline['5'] . '</td>';
  11. echo '<td>' . $logline['6'] . '</td>';
  12. echo '<td>' . $logline['7'] . '</td>';
  13. echo '<td>' . $logline['8'] . '</td>';
  14. echo '<td>' . $logline['9'] . '</td>';
  15. echo '<td>' . $logline['10'] . '</td>';
  16. echo '<td>' . $logline['11'] . '</td>';
  17. echo '<td>' . $logline['12'] . '</td>';
  18. echo '<td>' . $logline['13'] . '</td>';
  19. echo '<td>' . $logline['14'] . '</td>';
  20. echo '<td>' . $logline['15'] . '</td>';
  21. echo '</tr>';
  22. }
  23. }
  24. echo '</table>';
#define NULL (::rand() % 2)
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post November 3rd, 2010, 12:36 pm

Looks very good

Is it possible to let someone enter the day, month and year

This way you can view various dates
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, 12:41 pm

Yes, your going to want to look at $_GET, $_POST and forms.

http://www.w3schools.com/php/php_forms.asp
#define NULL (::rand() % 2)
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post November 3rd, 2010, 2:07 pm

I tried the following:

Code: [ Select ]
echo '<form action="select.php" method="post">';
echo 'Input Day: <input type="text" name="day" />';
echo 'Input Month: <input type="text" name="month" />';
echo 'Input Year: <input type="text" name="year" />';
echo '<input type="submit" />';
echo '</form> ';

$day = '$_REQUEST["day"]';
$month = '$_REQUEST["month"]';
$year = '$_REQUEST["year"]';


foreach ($log as $logline) {

if($logline['3'] == $day AND $logline['4'] == $month AND $logline['5'] == $year)

{
  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>';
  1. echo '<form action="select.php" method="post">';
  2. echo 'Input Day: <input type="text" name="day" />';
  3. echo 'Input Month: <input type="text" name="month" />';
  4. echo 'Input Year: <input type="text" name="year" />';
  5. echo '<input type="submit" />';
  6. echo '</form> ';
  7. $day = '$_REQUEST["day"]';
  8. $month = '$_REQUEST["month"]';
  9. $year = '$_REQUEST["year"]';
  10. foreach ($log as $logline) {
  11. if($logline['3'] == $day AND $logline['4'] == $month AND $logline['5'] == $year)
  12. {
  13.   echo '<td>' . $logline['0'] . '</td>';
  14.   echo '<td>' . $logline['1'] . '</td>';
  15.   echo '<td>' . $logline['2'] . '</td>';
  16.   echo '<td>' . $logline['3'] . '</td>';
  17.   echo '<td>' . $logline['4'] . '</td>';
  18.   echo '<td>' . $logline['5'] . '</td>';
  19.   echo '<td>' . $logline['6'] . '</td>';
  20.   echo '<td>' . $logline['7'] . '</td>';
  21.   echo '<td>' . $logline['8'] . '</td>';
  22.   echo '<td>' . $logline['9'] . '</td>';
  23.   echo '<td>' . $logline['10'] . '</td>';
  24.   echo '<td>' . $logline['11'] . '</td>';
  25.   echo '<td>' . $logline['12'] . '</td>';
  26.   echo '<td>' . $logline['13'] . '</td>';
  27.   echo '<td>' . $logline['14'] . '</td>';
  28.   echo '<td>' . $logline['15'] . '</td>';   
  29.   echo '</tr>';
  30. }
  31. }
  32. echo '</table>';


I see the input boxes and enter day, month year

When I submit nothing is displayed

Am I missing something

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, 5:42 pm

I found some little php errors

Once I cleared them up, everything is now working OK

By using a certain date now, I can view only the data for that date which is what I wanted

Thanks for all the suggestions

Thanks Bogey. That if statement did the trick and was quite simple to implement. I will remember this next time I am in the same situation

Again, 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:22 pm

Sorry SpooF

I should have thanked you for the IF statement that solved my problems

Between you and Bogey, I believe we came up with a very elegant and simple solution to my problem.

Not only can I view all data but now I can view selected data

Thanks again to both of you
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 5th, 2010, 12:49 am

I would appreciate if I could get some more help with this same project I am working on.

In my serialized row data, one of the elements is the IP address

The same IP address could appear in multiple rows if it is a return visitor.
If the IP address appears only in one row, then it is a unique visitor or first time visitor.

I have created an array for my serialized data rows and included an echo statement to check that I can indeed read the IPs in each row as follows:

foreach ($log as $logline) {
$visdata = array (
$logline['0'],
$logline['1'],
$logline['2'],
$logline['3'],
$logline['4'],
$logline['5'],
$logline['6'],
$logline['7'],
$logline['8'],
$logline['9'],
$logline['10'],
$logline['11'],
$logline['12'],
$logline['13'],
$logline['14'],
$logline['15']
);

echo $logline['9'], "<br/>";

}

When I run the script I do indeed see the same IP appearing more than once and unique IPs.

I can count the total number of rows so that I know the total for all the visits, return and unique.

What I would like to get is the following:

1) For the same multiple IPs, I want this to be grouped as one return vistior.
If there are say 7 same Mutiple IPs then this would count as 7 return visitors.
2) The number of unique IPs

I would then end up with something like the following:

Total Visits: 100
Return visits: 40
unique visits: 20

I would appreciate any suggestions

Thanks
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 5th, 2010, 1:07 am

Image


I assume $logline['9'] is the IP...
PHP Code: [ Select ]
<?php
$holder = array();
$total = 0;
foreach ($log as $logline)
{
    $visdata = array (
        $logline['0'],
        $logline['1'],
        $logline['2'],
        $logline['3'],
        $logline['4'],
        $logline['5'],
        $logline['6'],
        $logline['7'],
        $logline['8'],
        $logline['9'],
        $logline['10'],
        $logline['11'],
        $logline['12'],
        $logline['13'],
        $logline['14'],
        $logline['15']
    );
   
    if(in_array($logline['9'], $log))
    {
        $holder[$logline['9']] += 1;
    }
    $total++;
    echo $logline['9'], "<br/>";
}
?>
  1. <?php
  2. $holder = array();
  3. $total = 0;
  4. foreach ($log as $logline)
  5. {
  6.     $visdata = array (
  7.         $logline['0'],
  8.         $logline['1'],
  9.         $logline['2'],
  10.         $logline['3'],
  11.         $logline['4'],
  12.         $logline['5'],
  13.         $logline['6'],
  14.         $logline['7'],
  15.         $logline['8'],
  16.         $logline['9'],
  17.         $logline['10'],
  18.         $logline['11'],
  19.         $logline['12'],
  20.         $logline['13'],
  21.         $logline['14'],
  22.         $logline['15']
  23.     );
  24.    
  25.     if(in_array($logline['9'], $log))
  26.     {
  27.         $holder[$logline['9']] += 1;
  28.     }
  29.     $total++;
  30.     echo $logline['9'], "<br/>";
  31. }
  32. ?>


I don't even know if that works or even goes with the $log array... I think this might give an idea to someone... or maybe even you.

The main purpose of this post is the image up top :D ... and then I decided to put in something...
"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 5th, 2010, 9:09 pm

Hi Bogey

After reading your post, I did in fact get some ideas that worked out for me.

I first declared an IP Address only array called $ip = array()

From my serialized log data, as shown above, I took only the IP address elements and dynamically wrote them to the $ip array with the following:

$ip[]=$logline['9']

So now I had the $ip array with all the IP addresses, duplicates and singles to manipulate.

I then declared a new array that counted the frequency of the IP addresses in the $ip array as follows:

$dataout = array_count_values ($ip)

So now I new exactly how many times an IP(s) was duplicated, return visitors, and how many single IP(s), unique visitors there were.

I then set up a simple counter for the duplicated and single IP values that would increment depending on how many IPs were duplicated and which were not as follows;

PHP Code: [ Select ]
$dataout = array_count_values ($ip);
$r=0;
$u=0;
 
foreach ($dataout as $value)
{
If ($value > 1 )
{
$r++;
}
else
{
$u++;
}
}
 
echo "Return Visitors = ".$r." <br/><br/>";
echo "Unique vistors  = " .$u." <br/><br/>";
 
  1. $dataout = array_count_values ($ip);
  2. $r=0;
  3. $u=0;
  4.  
  5. foreach ($dataout as $value)
  6. {
  7. If ($value > 1 )
  8. {
  9. $r++;
  10. }
  11. else
  12. {
  13. $u++;
  14. }
  15. }
  16.  
  17. echo "Return Visitors = ".$r." <br/><br/>";
  18. echo "Unique vistors  = " .$u." <br/><br/>";
  19.  


Nothing fancy here, but it works like a charm.

Like you said, sometimes you just need someone else to come up with a suggestion and then your flying.

Thanks again
http://www.schembrionics.com
The Ultimate Solutions Center

Post Information

  • Total Posts in this topic: 26 posts
  • Users browsing this forum: No registered users and 252 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
 
cron
 

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