Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Statsman

    (@statsman)

    D’oh! I see above that I’m still working with $leaguesQuery – which I’ve already assigned to $leagueData.

    I went back in and changed it and it still didn’t work – but once I put it into a foreach it started working.

    Thanks for your help!

    Thread Starter Statsman

    (@statsman)

    Good suggestion – but not where the problem is.

    It was echoing the right query, so I took it a step further and did a foreach to echo the leagueID value – which it did. When I get to the next step where I’m populating my list table, that’s where I’m not getting any values.

    $leaguesQuery = get_leagues( ) ;
    
    foreach ( $leaguesQuery as $leagueInfo ) {
      echo "<p>".$leagueInfo->league_id."</p>";
    }

    This works and echoes the info in the db. If I put the echo into the following snippet I get nothing!

    if ( is_wp_error( $leaguesQuery ) ) {
      $error_string = $leaguesQuery->get_error_message();
      echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
      } else {
        $leagues = array() ;
        $leagueInfo = array() ;
        $leagueNum = 0 ;
         while ( $leagueData = mysql_fetch_array( $leaguesQuery ) ) {
           ++$leagueNum ;
           $leagueInfo['blog_id'] = $leaguesQuery->blog_id ;
           $leagueInfo['league_id'] = $leaguesQuery->league_id ;
           $leagueInfo['league_name'] = $leaguesQuery->league_name ;
           $leagueInfo['league_short_name'] = $leaguesQuery->league_short_name ;
            $leagueInfo['league_db_prefix'] = $leaguesQuery->league_db_prefix ;
            $leagueInfo['active'] = $leaguesQuery->active ;
            $leagueInfo['leagues_db_version'] = $leaguesQuery->leagues_db_version ;
            $leagues[$leagueNum] = $leagueInfo ;
       	unset ( $leagueInfo ) ;
        }
    }

    Instead of the While statement, I tried a foreach that came up with the same result. Obviously I’m not calling it right or something – but it worked just fine in September!

    Thread Starter Statsman

    (@statsman)

    I’m running the same code that has been working for about 5 years now – hence the deprecated stuff.

    I don’t have any reason for using the MySQL functions (except they always worked in the past) and I’d like to bring my site up to date with the more secure $wpdb functions but I’m not entirely sure where I’m going wrong here.

    I have this function:


    function get_leagues( ) {
    // Returns leagues information for network admin page
    global $wpdb ;

    $leagues_db_table = $wpdb->leagues ;
    if ( is_wp_error( $leagues_db_table ) ) {
    $leaguesQuery = $leagues_db_table->get_error_message() ;
    } else {
    $queryStr = "SELECT * FROM $leagues_db_table" ;
    $leagues = $wpdb->get_results( $queryStr ) ;
    if ( $leagues != null ) {
    return $leagues ;
    } else {
    return new WP_Error( 'Leagues Database Error', __("Could not find any leagues entered .") ) ;
    }
    }
    }

    … which seems to work just fine.

    Then I try to use the $leagues that is returned from it in this little snippet:


    $leaguesQuery = get_leagues( ) ;
    if ( is_wp_error( $leaguesQuery ) ) {
    $error_string = $leaguesQuery->get_error_message();
    echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
    } else {
    $leagues = array() ;
    $leagueInfo = array() ;
    $leagueNum = 0 ;
    while ( $leagueData = mysql_fetch_array( $leaguesQuery ) ) {
    ++$leagueNum ;
    $leagueInfo['blog_id'] = $leaguesQuery->blog_id ;
    $leagueInfo['league_id'] = $leaguesQuery->league_id ;
    $leagueInfo['league_name'] = $leaguesQuery->league_name ;
    $leagueInfo['league_short_name'] = $leaguesQuery->league_short_name ;
    $leagueInfo['league_db_prefix'] = $leaguesQuery->league_db_prefix ;
    $leagueInfo['active'] = $leaguesQuery->active ;
    $leagueInfo['leagues_db_version'] = $leaguesQuery->leagues_db_version ;
    $leagues[$leagueNum] = $leagueInfo ;
    unset ( $leagueInfo ) ;
    }
    }

    … and get nothing!

    I’m just a bit of a hacker trying to make my way through – there’s obviously something (obvious!) that I’m missing.

    Any help would be appreciated.

    Thanks

    Forum: Fixing WordPress
    In reply to: Access denied
    Thread Starter Statsman

    (@statsman)

    Thanks for the reply.

    Think I’ve narrowed the issue down to me using mysql_query instead of $wpdb. I’ve eliminated that particular error but am now having issues with not getting any results from my query.

    This works without error:

    function get_leagues( ) {
    // Returns leagues information for network admin page
    global $wpdb ;
    $leagues_db_table = $wpdb->spc_leagues ;
    if ( is_wp_error( $leagues_db_table ) ) {
    $leaguesQuery = $leagues_db_table->get_error_message() ;
    } else {
    $queryStr = “SELECT * FROM $leagues_db_table” ;
    $leagues = $wpdb->get_results( $queryStr ) ;
    if ( $leagues != null ) {
    return $leagues ;
    } else {
    return new WP_Error( ‘Leagues Database Error’, … ) ;
    }
    }
    }

    But then when I go to use the result I get “No leagues found” and it generates an error: Warning: mysql_fetch_array() expects parameter 1 to be resource, array given in /home/ … spc-leagues.php on line 316.

    Is there an equivalent to the mysql function that I should be using since it was the original mysql query that broke my site?

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