Skip to content

Bug php + mysql #105

@iLenTheme

Description

@iLenTheme

Hi, your theme is very nice ... there is a problem that look:

  1. Install wordpress
  2. Install the theme Highwind
  3. friend Add the following mysql table
CREATE TABLE IF NOT EXISTS `wp_forum_hits` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(15) NOT NULL,
  `views` int(15) NOT NULL,
  `last_viewed` datetime NOT NULL,
  `modified` int(11) DEFAULT NULL,
  UNIQUE KEY `ID` (`ID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=16 ;
  1. In the functions.php file add the following code
function hits_forum(){

    global $wpdb;

    if(!is_singular()) return;
    $post_ID = get_the_ID();
    $table_name = $wpdb->prefix . 'forum_hits';
    $counter = ($wpdb->get_row(" SELECT views FROM  $table_name WHERE post_id = $post_ID ")->views) + 1;
    echo $counter;
    if( ! $wpdb->query("UPDATE $table_name  SET views = $counter ,last_viewed = '".date("Y-m-d H:m:i")."',modified=".time()." WHERE post_id = $post_ID") ){
        @$wpdb->query("insert into $table_name values(0,$post_ID,1,'".date("Y-m-d H:m:i")."',".time().")");
    }
}
add_action('wp_head', 'hits_forum' );
  1. Go to the post 'Hello world!'
  2. Refresh the page and see the counter on the top

I created a simple counter visits but apparently your theme because it increases the double counting 1,3,5,7 .... instead of going counting one by one 1,2,3,4,5. .... I have a lot reviewed this issue and seems to be a bug in chrome, firefox, etc when ay an image that is not loading While this makes 2 times send the request and about some wordpress theme.
If active default wordpress theme 'twentyfifteen' and add the code in the functions.php file and has perfectly well but tells active 'highwind' starts counting wrong. You can fix this bug that has your theme ?, I put items that have to do with the case. It is not a matter of wordpress but something about loading an image that is empty and php with mysql do a double request, please read ...

http://forums.devshed.com/php-development-5/counters-increment-2-instead-1-a-486251.html
http://www.sitepoint.com/forums/showthread.php?362404-WEIRD!-PHP-code-executed-twice-because-of-spacer-gif!
http://forums.phpfreaks.com/topic/37983-solved-query-increments-database-twice/
https://code.google.com/p/chromium/issues/detail?id=64810

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions