WordPress.org

Ready to get started?Download WordPress

Forums

How to pull a record from the table in MySQL (5 posts)

  1. shadow
    Member
    Posted 8 years ago #

    I am using Kafkaesqui's Download Manager to keep a record of how many downloads of the theme zips are going through the Shadows site. I can manually go into PHPmyadmin and see that it is currently 10,137 but I would like to make this an automated process so it just keeps itself updated.

    Ideally, I wanted to show a record of the top 20 as well, but the coding needed is a bit beyond me.

    If anyone knows an easy way to show the total of the downloads, it would be much appreciated.

    Thanks :)

  2. ifelse
    Member
    Posted 8 years ago #

    Try adding the following to the bottom of the plugin file(download-mgr.php):

    <?php
    function get_download_count($file_name){
    global $wpdb;
    $dl_count = count($wpdb->get_col("SELECT id FROM $wpdb->downloads WHERE file_name = '$file_name'"));
    echo $dl_count;
    }
    ?>

    And then, call get_download_count($file_name) at the point where you want the count outputted.

    BTW, quick warning: the code is untested and I don't use Kaf's plugin but I've had a look at the plugin code and it should work.

  3. shadow
    Member
    Posted 8 years ago #

    Hi ifelse,

    Thanks for taking the time to work this out for me. Unfortunately, it is not working as yet and I am receiving this message in the output

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE file_name = ''' at line 1]
    SELECT id FROM WHERE file_name = ''
    0

    I called it using this
    <?php get_download_count($file_name); ?>

    and placed your above code at the end of the plugin file [download-mgr.php] as you stated.

  4. Kafkaesqui

    Posted 8 years ago #

    Actually the code above won't work. The downloads table is not one WordPress is aware of, hence it's not available through $wpdb (well, normally).

    One option is to reuse some of the *hack* found here:

    http://wordpress.org/support/topic/47684

    Another is to replace ifelse's suggestion with the following:

    http://guff.szub.net/source/sample-50452.php

    <?php get_download_count(); ?>
    --This will display a count for all files logged.

    <?php get_download_count('file-name.zip'); ?>
    --This will display a count for just that file.

    <?php $dl_cnt = get_download_count('file-name.zip', false); ?>
    --This returns the count, assigning it to the $dl_cnt variable.

  5. shadow
    Member
    Posted 8 years ago #

    Thank you very much Kafkaesqui. That seems to have done the trick.
    Much appreciated :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags