views-per-pagina-per-dag

Gesponsorde koppelingen

PHP script bestanden

  1. views-per-pagina-per-dag

« Lees de omschrijving en reacties

/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/
page_recs.php
/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?
    //-- ================================== --//
    //-- Auth: Bas Kreleger            --//
    //-- Web: www.phphulp.nl        --//
    //-- Descr: records page hits per day    --//
    //-- ==================================    --//
    
    //-- USE THIS MYSQL TABLE --//
    /*
    CREATE TABLE page_recs (
      id int(11) NOT NULL auto_increment,
      url varchar(250) NOT NULL default '',
      views int(11) NOT NULL default '0',
      cdate varchar(10) NOT NULL default '',
      PRIMARY KEY  (id)
    ) TYPE=MyISAM;
    */
    //--------------------------//
    
    //-- make database connection (if there's none yet) (or require db file)
    //-- fill this in yourself!

    
    $dbuser = "user"; // your mysql username
    $dbpass = "pass"; // your mysql password
    $dbhost = "localhost"; // the host you connect to
    $dbname = "database_name"; // your mysql database name
        
    //-- connect

    $dbconn = mysql_connect($dbhost, $dbuser, $dbpass);
    //-- select database
    mysql_select_db($dbname, $dbconn) or die(mysql_error());

    //-- end database connection
    //-- ================ --/
    
    //-- define table

    $rec_table = "page_recs";
    
    //-- set page url
    $rec_url = "$PHP_SELF";
    
    //-- set current date
    $rec_date = date("d.m.Y");
    
    //-- check database for existing record
    $sql = "SELECT id FROM $rec_table WHERE url = '$rec_url' AND cdate = '$rec_date'";
    $res = mysql_query($sql);
    
    //-- check if there's any result
    if (mysql_num_rows($res) >= 1)
    {

        $rec_sql = "UPDATE $rec_table SET views = views+1 WHERE url = '$rec_url'";
        //-- all errors should be hidden for visitors
        //-- if the script does not work, remove the @ before mysql_query
        //-- so errors will be displayed. (to detect what's wrong)

        @mysql_query($rec_sql);
        unset($rec_sql);
    }

    else
    {
        $rec_sql = "INSERT INTO $rec_table (id, url, views, cdate) VALUES ('', '$rec_url', '1', '$rec_date')";
        //-- all errors should be hidden for visitors
        //-- if the script does not work, remove the @ before mysql_query
        //-- so errors will be displayed. (to detect what's wrong)

        @mysql_query($rec_sql);
    }

?>


/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/
show_recs.php
/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/=/

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?
    //-- make database connection (if there's none yet) (or require db file)
    //-- fill this in yourself!

    
    $dbuser = "user"; // your mysql username
    $dbpass = "pass"; // your mysql password
    $dbhost = "localhost"; // the host you connect to
    $dbname = "database_name"; // your mysql database name
        
    //-- connect

    $dbconn = mysql_connect($dbhost, $dbuser, $dbpass);
    //-- select database
    mysql_select_db($dbname, $dbconn) or die(mysql_error());

    //-- end database connection
    //-- ================ --/

    
    // post

    if (!$HTTP_POST_VARS[submit])
    {

        $dedatum = date("d.m.Y");
        
        $sdd = date("d");
        $smm = date("m");
        $syy = date("Y");
    }

    else
    {
        $dedatum = $HTTP_POST_VARS[dd] . "." . $HTTP_POST_VARS[mm] . "." . $HTTP_POST_VARS[yy];
        
        $sdd = $HTTP_POST_VARS[dd];
        $smm = $HTTP_POST_VARS[mm];
        $syy = $HTTP_POST_VARS[yy];
    }

    
    // get data
    $sql = "SELECT url,views FROM php_recs WHERE cdate = '$dedatum'";
    $res = mysql_query($sql);
    
    // show form
    echo "<form method=\"post\" action=\"$PHP_SELF\">";
    echo "Zoek op een andere datum:<br>";
    echo "<i>Statistieken van ";
    echo "<select name=\"dd\">";
    
    // days
    for ($i = 1; $i <= 31; $i++)
    {

        if ($i < 10)
            $si = "0" . $i;
        else
            $si = $i;
        
        if ($sdd == $si)
            echo "<option value=\"$si\" selected>$si</option>";
        else
            echo "<option value=\"$si\">$si</option>";
    }

    echo "</select> ";
    echo "<select name=\"mm\">";
    // januari
    if ($smm == "01")
        echo "<option value=\"01\" selected>Jan</option>";
    else
        echo "<option value=\"01\">Jan</option>";
    
    // februari
    if ($smm == "02")
        echo "<option value=\"02\" selected>Feb</option>";
    else
        echo "<option value=\"02\">Feb</option>";
        
    // maart
    if ($smm == "03")
        echo "<option value=\"03\" selected>Mar</option>";
    else
        echo "<option value=\"03\">Mar</option>";
    
    // april
    if ($smm == "04")
        echo "<option value=\"04\" selected>Apr</option>";
    else
        echo "<option value=\"04\">Apr</option>";
    
    // mei
    if ($smm == "05")
        echo "<option value=\"05\" selected>Mei</option>";
    else
        echo "<option value=\"05\">Mei</option>";
        
    // juni
    if ($smm == "06")
        echo "<option value=\"06\" selected>Jun</option>";
    else
        echo "<option value=\"06\">Jun</option>";
    
    
    // juli
    if ($smm == "07")
        echo "<option value=\"07\" selected>Jul</option>";
    else
        echo "<option value=\"07\">Jul</option>";
    
    
    // augustus
    if ($smm == "08")
        echo "<option value=\"08\" selected>Aug</option>";
    else
        echo "<option value=\"08\">Aug</option>";
    
    // september
    if ($smm == "09")
        echo "<option value=\"09\" selected>Sep</option>";
    else
        echo "<option value=\"09\">Sep</option>";
    
    
    // oktober
    if ($smm == "10")
        echo "<option value=\"10\" selected>Okt</option>";
    else
        echo "<option value=\"10\">Okt</option>";
    
    // november
    if ($smm == "11")
        echo "<option value=\"11\" selected>Nov</option>";
    else
        echo "<option value=\"11\">Nov</option>";
    
    // december
    if ($smm == "12")
        echo "<option value=\"12\" selected>Dec</option>";
    else
        echo "<option value=\"12\">Dec</option>";
    echo "</select> ";
    
    echo "<select name=\"yy\">";
    for ($i = 2003; $i <= 2030; $i++)
    {

        if ($syy == $i)
            echo "<option value=\"$i\" selected>$i</option>";
        else
            echo "<option value=\"$i\">$i</option>";
    }

    echo "</select> ";
    echo "<input type=\"submit\" value=\"tonen\" name=\"submit\">";
    echo "</form><p>";
    
    
    // show result or no result    
    echo "<table border=1 cellspacing=0 cellpadding=5>";
    echo "<tr>";
    echo "<th>url</th>";
    echo "<th>views</th>";
    echo "</tr>";
    
    if (mysql_num_rows($res) >= 1)
    {

        while ($row = mysql_fetch_array($res))
        {

            echo "<tr>";
            echo "<td>$row[url]</td>";
            echo "<td>$row[views]</td>";
            echo "</tr>";
        }
    }

    else
    {
        echo "<tr><td colspan=\"2\"><i>Er zijn geen statistieken bekend van </i><b>$dedatum</b>.</td></tr>";
    }

    
    echo "</table>";
?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.