Forums

[resolved] sql query help (5 posts)

  1. islandcastaway
    Member
    Posted 1 year ago #

    Can someone please help me with this sql query:

    $image = $wpdb->get_var($wpdb->prepare("SELECT image FROM $wpdb->wordtube WHERE vid = $wordtubeId"));

    I am getting this error:

    WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 for query SELECT image FROM wordtube WHERE vid = made by require, require_once, include, boposts_show

    The query is working but I get this in php-errors.log

    What am I missing?

  2. alxvallejo
    Member
    Posted 6 months ago #

    Probably too late for this one but have you tried WHERE vid = '$wordtubeId'"));?

  3. islandcastaway
    Member
    Posted 6 months ago #

    RE: alxvallejo wrote:

    Probably too late for this one but have you tried WHERE vid = '$wordtubeId'"));?

    I thought that I posted my fix, guess not, and not sure why @alxvallejo post isn't here I just got via email subscription.

    Newayz I got it fixed with

    $image = $wpdb->get_var("SELECT image FROM ($wpdb->wordtube) WHERE vid = ($wordtubeId)");}

    Cheers

  4. alxvallejo
    Member
    Posted 6 months ago #

    Just curious, were you placing this inside a function? I'm fairly new at plugin development and I'm trying to figure out if I'm inserting variables correctly.

  5. islandcastaway
    Member
    Posted 6 months ago #

    Yes.

    To be specific I added it to the plugin "best related posts" to grab the thumbnail from a post that had "wordtube" content.

    I have no clue if my code is 100% correct, but its working and it doesn't throw any errors.

    Cheers

Topic Closed

This topic has been closed to new replies.

About this Topic