I have a problem. I've got a PHP script that tracks individual file downloads, and I'm looking for a way to display that number in individual posts. I've got a half-baked solution- a plain ol' MySQL manual connection script, but I'm trying to convert it to use as a Wordpress plugin (I want it to use WPDB). I've tried to convert it, but I don't know what the Wordpress alternative to 'mysql_fetch_array.' Anyways, I've included the original script below, as well as my progress on a Wordpress-friendly version.
Plain Version:
function mb_download_count() {
global $post;
if (get_post_meta($post->ID, 'zipname', TRUE)) {
$namemeta = get_post_meta($post->ID, 'zipname', TRUE);
require $_SERVER['DOCUMENT_ROOT'].'/downloader-connect.php';
$result = mysql_query("SELECT * FROM mb_download_manager
WHERE filename='".$namemeta.".zip'");
// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table
if ($row['downloads'] == '') { echo ('0'); } else {
echo $row['downloads']; }
} else { }
}
Wordpress-friendly Version so far:
function mb_download_count() {
global $wpdb;
global $post;
if (get_post_meta($post->ID, 'zipname', TRUE)) {
$namemeta = get_post_meta($post->ID, 'zipname', TRUE);
$result = $wpdb->query("SELECT * FROM mb_download_manager
WHERE filename='".$namemeta.".zip'");
$row = mysql_fetch_array( $result );
if ($row['downloads'] == '') { echo ('0'); } else {
echo $row['downloads']; }
} else { }
}