• Yeah, I know, there’s a ton of posts on this and I believe I’ve read all of them, or as many as I could find. I’ll try to give all the information needed to solve this: After 2 days, I’m completely stuck.

    (1) I was trying to do a variation on a plug-in tutorial for integrating osCommerce and WordPress by getting random product images to show in the side bar. The url of the tutorial is http://net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from-scratch/

    (2) He was trying to get random product pics and links to show in sidebar. I’m trying to get osCommerce categories to show in the sidebar so that the WP and osCommerce match on the left column.

    (3) Based on the tutorial (and based on not knowing if the osCommerce database will always be on the same server) I did most of the tutorial, then borrowed the SQL query almost directly from the box module (in English) from osCommerce. The SQL query works outside of WP, but not here. I even tested to make sure that the query was actually returning results and it is.

    <?php
    function osccat_admin() {
        include('osc_category_admin.php');
    }
    function osccat_admin_actions() {
        add_options_page("OSCommerce Category List", "OSCommerce Category List", "manage_options", "oscommerce-category-list", "osccat_admin");
    }
      function tep_db_fetch_array($db_query) {
        return mysql_fetch_array($db_query, MYSQL_ASSOC);
      }
    function osccat_getlist() {
    global $wpdb;
    //Connect to the OSCommerce database
    $oscommercedb = new wpdb(get_option('osccat_dbuser'),get_option('osccat_dbpwd'), get_option('osccat_dbname'), get_option('osccat_dbhost'));
    $category_list='';
    $categories_query = $oscommercedb->get_results("select c.categories_id, cd.categories_name, c.parent_id from categories c, categories_description cd where c.parent_id = '0' and c.categories_id = cd.categories_id order by sort_order, cd.categories_name") or die(mysql_error());
    print_r($categories_query);
    while ($categories = mysql_fetch_array($categories_query, MYSQL_ASSOC)) {
    $category_list.='<li><a href="storeindex.php?osCsid=' . $categories['categories_id'] . '">' . $categories['categories_name'] . '</a></li>' . "\n";
    }
    $category_list='<ul>' . "\n" . $category_list . '</ul>' . "\n";
    
    return $category_list;
    }
    
    add_action('admin_menu', 'osccat_admin_actions');
    ?>

    Trying to insert code for the first time, so…

    Modifications are mostly about trying to pinpoint the error..

Viewing 4 replies - 1 through 4 (of 4 total)
  • I had the same problem and I’m in Brighton. PM me if you want the solution. 😀

    Thread Starter seanrice

    (@seanrice)

    Sorry, BrightonPHP. That didn’t work. 😉

    Thread Starter seanrice

    (@seanrice)

    Obviously, the consistent problem that results in the error, “mysql_fetch_array() expects parameter 1 to be resource, array given in /home/gamestow/public_html/DEV/wp-content/plugins/rasa_osC_categories/osccat_admin.php on line 37” is a difference between what mysql_fetch_array expects and what it’s being given.

    I can do this with a direct connection to mysql, but I’d rather learn how I’m doing it wrong within the WP environment.

    I feel that I’ve done my homework and have gone through the forums both here and outside as well as the codex (which, btw, is singularly unhelpful with the subject of $wpdb)

    After staring at this, I just can’t figure out what’s wrong with the code. I’d appreciate some help. Thanks. 😀

    Thread Starter seanrice

    (@seanrice)

    OK, the following variation on the code works to do exactly what I wanted to do, but with the osCommerce database on the same server. That’s not always going to be the case. This issue is that I want to do this with the $wpdb instantiated class rather than straight php/mysql and I cant figure out what I’m doing wrong.

    THIS works:

    <?php
    function osccat_getlist() {
    global $wpdb;
    $category_list='';
    $sql = sprintf("select c.categories_id, cd.categories_name, c.parent_id from categories c, categories_description cd where c.parent_id = '0' and c.categories_id = cd.categories_id");
    $result = mysql_query($sql);
    if (!$result) {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $sql;
        die($message);
    }
    
    //$categories_query=$wpdb->get_results($sql);
    while ($categories = mysql_fetch_array($result)) {
    $category_list.='<li><a href="storeindex.php?osCsid=' . $categories['categories_id'] . '">' . $categories['categories_name'] . '</a></li>' . "\n";
    }
    $category_list='<ul>' . "\n" . $category_list . '</ul>' . "\n";
    mysql_free_result($result);
    return $category_list;
    }
    
    add_action('admin_menu', 'osccat_admin_actions');

    The OP code does not.

    Any love out there for me? 😀

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

The topic ‘Yet another "mysql_fetch_array() expects parameter 1 to be resource" issue…’ is closed to new replies.