iNoob Posted May 23, 2011 Share Posted May 23, 2011 Hello. I am trying to build a PHP hit counter for each game ID in the column of my database when visited, and updating the 'fldPlays' column by +1 to show how many people visited each page. I have a huge table with a list of data, but I'll show just 3 of the columns I have. Here they are: fldID | fldData | fldPlays =================== 32145 Data1 0 21543 Data2 0 75855 Data3 0 36623 Data4 0 12471 Data5 0 =================== I am trying to increase the counter number at the 'fldPlays' column to show how many users had played each game by identifying the ID first. So for example: User types in 'http://www.mysite.com/games.php?id=32145' in the address bar for the 'Data1' game, and then once the user enters that particular page with that ID 32145 as you see in the URL, it adds 1 to the 'fldPlays' in that row. Overall, when I echo out 'fldPlays' as text in each page, it shows how many people actually played that page. Just to let everybody know that I am still learning PHP and I am new to counters as well. My guess to start the PHP counter is to fetch the ID of that URL, you would have to get id like this: <?php if(isset($_GET['id'])) { $conn = mysql_connect("database", "username", "password"); mysql_select_db("data"); $game_id = $_GET['id']; $sql = "SELECT * FROM dbname WHERE fldID='$game_id' LIMIT 1"; ?> If anyone needs clarification, I will reply. Thanks for helping. Quote Link to comment https://forums.phpfreaks.com/topic/237234-php-hit-counter-for-each-id-page/ Share on other sites More sharing options...
anupamsaha Posted May 23, 2011 Share Posted May 23, 2011 Try the following: <?php if(isset($_GET['id'])) { $conn = mysql_connect("database", "username", "password"); mysql_select_db("data"); $game_id = (int) $_GET['id']; // typecast to integer type to have a safe input from the URL querystring $sql = "UPDATE `dbname` SET `fldPlays` = `fldPlays` + 1 WHERE `fldID`='$game_id' LIMIT 1"; mysql_query($sql) or die(mysql_error()); //---- your rest of the code goes here ---- // ?> Quote Link to comment https://forums.phpfreaks.com/topic/237234-php-hit-counter-for-each-id-page/#findComment-1219133 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.