Forums

[resolved] Basic wpdb query not working; no results (4 posts)

  1. ixwa
    Member
    Posted 10 months ago #

    global $wpdb;
    $gallery = $wpdb->get_row("SELECT * FROM $wpdb->wp_ngg_gallery WHERE gid = 3");
    echo $gallery->slug;

    Why doesn't this work? Isn't this the most rudimentary type of wpdb query statement? I should be getting results (checked the table/column names in phpmyadmin). I also checked if $gallery exists after and it comes back negative.

    Tried get_var, get_results too--nada.

    Huh???

  2. ixwa
    Member
    Posted 10 months ago #

    Interestingly, using a standard WP table like wp_links works.

    Does anyone know if the NextGen gallery mySQL tables are somehow permission-based?? That is just weird.

  3. ixwa
    Member
    Posted 10 months ago #

    If you want something done properly DO IT YOURSELF.

    For anyone who encountered this same behavior, behold the simple, stupid answer: The wordpress codex example ONLY works for WP-specific tables. Any other types of tables created by plugins or yourself use the basic mySQL syntax format:

    $mystuff = $wpdb->get_row("SELECT * FROM my_table_name WHERE something = something");

    No $wpdb->table_name, no prefix junk, and no concatenated PHP strings.

    Be careful what you read in the codex...it's not all there.

  4. cylimomo
    Member
    Posted 3 months ago #

    Thanks so much..! I've got the same problem and solved it as what you did. I feel so stupid after spending 2hrs fixing the bug...

Reply

You must log in to post.

About this Topic