September 16th, 2000, 05:10 PM
-
Just wondering if someone can point me in the right direction of incrementing a counter in a MySQL feild when a preformed query displays results and the link gets clicked.
Thanks in advance
September 16th, 2000, 11:40 PM
-
If the page which the link goes to is yours then u can put a query at the top of the page along the lines of...
mysql_query($database,"UPDATE table_name set count=count+1 where link=$link);
if you don't control the page it goes to then you will need to make a seperate page which the link will go to. Like this..
<?
mysql_query($database,"UPDATE table_name set count=count+1 where link=$link);
header("Location: $link");
exit;
?>
that will then update your mysql counter and forward the user to $link.
Basil
September 17th, 2000, 08:16 AM
-
I want to include something like this in a site i'm working on. But what can you do about reloads etc. ? Because people can press reload 5 times to screw everything up..
September 17th, 2000, 12:01 PM
-
Can anyone tell me why this won't work? (I'm new to php btw).
<?php
$link = mysql_connect ("", "login", "password");
mysql_select_db ("database");
$result = mysql_query ("SELECT link FROM links WHERE number=$locn");
$row = mysql_fetch_array($result);
mysql_query($link,"UPDATE links set counter=counter+1 where link=$row);
header("Location: $row["link"]);
echo "nn";
mysql_close ($link);
?>
September 17th, 2000, 12:52 PM
-
About the reloads --
Your best bet is to use a text file to hold the counter, and lock the file for maybe 1 or 2 seconds after each access... that way people can't reload hundreds of times and **** it up. And about that header() thing, I think you have to send header() before any other PHP statements.
------------------
To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson
September 17th, 2000, 04:34 PM
-
You can do any php code you want before you send a header - you just can't output anything (no print or echo statments) before sending a header.
thecrazed1: your problem lies (I believe) in this line
header("Location: $row["link"]);
First of all, that should go outside the php tags. Second, it should read
header("Location: <?php echo $row["link"]; ?>"); What error message are you receiving?
September 17th, 2000, 10:36 PM
-
First of all..
header() does not go outside the php tags
TheCrazed1, here is what i think your code should read..
<?php
mysql_connect ("localhost", "login", "password");
mysql_select_db ("database");
$result = mysql_query ("SELECT link FROM links WHERE number=$locn");
while($row = mysql_fetch_array($result)){
$link = $row["link"];
mysql_query("UPDATE links set counter=counter+1 where link=$link");
}
mysql_close();
header("Location: $link");
exit;
?>
Please note that you should not echo anything after use of header()
Basil
[This message has been edited by 'tantrum (edited September 17, 2000).]
September 18th, 2000, 03:20 AM
-
Can you tell me how to do the file locking ???
Or any site for references ??
Tnx before !!
See ya
------------------
CyberOsc
sphmjf_oscario@gurlmail.com
** It's the world of Oscario **
September 18th, 2000, 09:35 AM
-
Okay thanks everyone for your help thus far the script seems to work without any errors being generated except it doesn't seem to update the counter in the database. The feild type is set as INT and thats about it. Any Ideas? Once again thanks for the help so far!