• Resolved AronMS

    (@aronms)


    Is there an equivalent to mysql_fetch_assoc or while mysql_fetch_array using the $wpdb class?

    For example:

    while ($row = mysql_fetch_assoc($results)){
        // Do code to process db results here.
    }

    How would I write this using the $wpdb class?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    As you know, mysql_fetch_assoc() processes the results returned by mysql_query(). $wpdb class methods typically return results of a query to the wordpress database similar to what mysql_query() would do. $wpdb class methods do not process such results as mysql_fetch_assoc() would do, so there is no true equivalent.

    What I usually do with the results from $wpdb queries that is similar to your example is:

    foreach ($results as $row) {
        // Do code to process db results here.
    }

    Some $wpdb methods have an option to return results in various forms. I now wonder if one of these would be compatible to pass to mysql_fetch_assoc(). Something to toy with when I’m bored!

Viewing 1 replies (of 1 total)
  • The topic ‘Is there an equivalent to mysql_fetch_assoc using $wpdb’ is closed to new replies.