• Cole Slaw

    (@nthorin)


    I can’t see the difference in these two PHP syntaxes.

    This one doesn’t work. Generates a error message that says “Object of class stdClass could not be converted to string”

    $query = "SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'trash'";
    $pages = $wpdb->get_results($query);
    foreach( $pages as $p ) {
    	echo "xxx";
    }

    This one works.

    $query = "SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'trash'";
    $result = $wpdb->get_results($query);
    foreach ($result as $user) {
        echo $user->ID;
    	echo "xxx";
    }

    Is the world, or me, going mad?

  • The topic ‘Difference in PHP syntax’ is closed to new replies.