tomtom Posted June 7, 2008 Share Posted June 7, 2008 Hey. I've done it a million times before but it just doesn't seem to work this time. I've made a VERY simple script to update the amount of hits a page has had in mysql. I've set the attribute `hits` to INT. Here's my code. The weird thing is...it'll update the page the first time, from 0 to 1. But then it won't go any higher than 1. <?php $get_home = mysql_query("SELECT * from `pages`"); while($home = mysql_fetch_array($get_home)) { $hits = $home[hits]+1; $update = mysql_query("UPDATE `pages` SET `hits` = '" . $hits . "' WHERE `id` = '$home[id]'"); } ?> Link to comment https://forums.phpfreaks.com/topic/109118-solved-hits/ Share on other sites More sharing options...
ILYAS415 Posted June 7, 2008 Share Posted June 7, 2008 instead of $update = mysql_query("UPDATE `pages` SET `hits` = '" . $hits . "' WHERE `id` = '$home[id]'"); try using... $update = mysql_query("UPDATE `pages` SET `hits`='$hits' WHERE `id` = '$home[id]'"); Link to comment https://forums.phpfreaks.com/topic/109118-solved-hits/#findComment-559741 Share on other sites More sharing options...
thebadbad Posted June 7, 2008 Share Posted June 7, 2008 You should quote your array keys, since they are strings. $home['hits'] and $home['id'], but not sure it will change any functionality. Link to comment https://forums.phpfreaks.com/topic/109118-solved-hits/#findComment-559745 Share on other sites More sharing options...
tomtom Posted June 7, 2008 Author Share Posted June 7, 2008 Nice try, but nope...didnt work Link to comment https://forums.phpfreaks.com/topic/109118-solved-hits/#findComment-559864 Share on other sites More sharing options...
DarkWater Posted June 7, 2008 Share Posted June 7, 2008 mysql_query("UPDATE pages SET hits=hits+1 WHERE id = {$home['id']}") OR die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/109118-solved-hits/#findComment-559890 Share on other sites More sharing options...
tomtom Posted June 7, 2008 Author Share Posted June 7, 2008 Cheers matey Link to comment https://forums.phpfreaks.com/topic/109118-solved-hits/#findComment-559948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.