Bazu sam kreirao ovako:
Code:
CREATE TABLE `click_stats` (
`id` int(8) auto_increment PRIMARY KEY,
`hits1` int(8),
`hits2` int(8),
`hits3` int(8)
);
CREATE TABLE `click_stats` (
`id` int(8) auto_increment PRIMARY KEY,
`hits1` int(8),
`hits2` int(8),
`hits3` int(8)
);
a sama skriptica izgleda ovako:
Code:
<?php
//definisanje sajtova na koje ide traffic
$url1 = "http://www.google.com/";
$url2 = "http://www.yahoo.com/";
$url3 = "http://www.msn.com/";
//konektuj se na mysql server i izaberi odgovarajucu bazu
@ $db = mysql_connect('localhost', 'xxxxx', 'xxxxx');
if (!$db) {
echo 'Greska! Konekcija sa bazom trenutno nije moguca. Molimo Vas pokusajte ponovo kasnije.';
exit;
}
mysql_select_db ('xxxxx');
$click_stats = mysql_query ("SELECT * from click_stats");
$t1 = mysql_fetch_array ($click_stats);
$hits1 = $t1['hits1'];
$hits2 = $t1['hits2'];
$hits3 = $t1['hits3'];
if (($hits1 <= $hits2) && ($hits1 <= $hits3)) {
$hits1 = $hits1++;
mysql_query("UPDATE click_stats SET hits1='$hits1' WHERE id=1");
header("Location: $url1");
}
elseif (($hits2 < $hits1) && ($hits2 <= $hits3)) {
$hits2 =$hits2++;
mysql_query("UPDATE click_stats SET hits2='$hits2' WHERE id=1");
header("Location: $url2");
}
elseif (($hits3 < $hits1) || ($hits3 < $hits2)) {
$hits3 = $hits3++;
mysql_query("UPDATE click_stats SET hits3='$hits3' WHERE id=1");
header("Location: $url3");
}
?>
<?php
//definisanje sajtova na koje ide traffic
$url1 = "http://www.google.com/";
$url2 = "http://www.yahoo.com/";
$url3 = "http://www.msn.com/";
//konektuj se na mysql server i izaberi odgovarajucu bazu
@ $db = mysql_connect('localhost', 'xxxxx', 'xxxxx');
if (!$db) {
echo 'Greska! Konekcija sa bazom trenutno nije moguca. Molimo Vas pokusajte ponovo kasnije.';
exit;
}
mysql_select_db ('xxxxx');
$click_stats = mysql_query ("SELECT * from click_stats");
$t1 = mysql_fetch_array ($click_stats);
$hits1 = $t1['hits1'];
$hits2 = $t1['hits2'];
$hits3 = $t1['hits3'];
if (($hits1 <= $hits2) && ($hits1 <= $hits3)) {
$hits1 = $hits1++;
mysql_query("UPDATE click_stats SET hits1='$hits1' WHERE id=1");
header("Location: $url1");
}
elseif (($hits2 < $hits1) && ($hits2 <= $hits3)) {
$hits2 =$hits2++;
mysql_query("UPDATE click_stats SET hits2='$hits2' WHERE id=1");
header("Location: $url2");
}
elseif (($hits3 < $hits1) || ($hits3 < $hits2)) {
$hits3 = $hits3++;
mysql_query("UPDATE click_stats SET hits3='$hits3' WHERE id=1");
header("Location: $url3");
}
?>
Dakle, kao sto se vidi, svaki put uzimam vrednost iz baze i uvecevam je za 1, a zatim je vracam u bazu.
Medjutim, problem je u tome sto vrednosti nece da se update-uju, a ja ne znam gde gresim jer mi ovo ovako izgleda ok.
Ako ima nekoga raspolozenog da pogleda skriptu i ukaze mi na gresku...
Internet forumi su kao javni toalet... udje ko želi, ispiša se gde poželi, i ode...