• shadow

    (@shadow)


    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 ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • ifelse

    (@ifelse)

    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.

    Thread Starter shadow

    (@shadow)

    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.

    Kafkaesqui

    (@kafkaesqui)

    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:

    https://www.ads-software.com/support/topic/47684

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

    https://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.

    Thread Starter shadow

    (@shadow)

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to pull a record from the table in MySQL’ is closed to new replies.