MySql MultiLine Query doesn't work? (2 posts)

  1. Wolfull
    Posted 7 years ago #

    I'm using the following query to get a users rank
    $userPos = $wpdb->query("SELECT points INTO @score FROM wp_gameUsers WHERE id=1; SELECT COUNT(*) FROM wp_gameUsers WHERE points > @score;");

    Executes fine as a standard mySQL query, but when I move it into wordpress to process it faults at the ';'.

    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 '; SELECT COUNT(*) FROM wp_gameUsers WHERE points > @score' at line 1]

    Anyone have any idea of how to work around this?

  2. mrmist
    Forum Janitor
    Posted 7 years ago #

    Possibly the wpdb->query only allows one query to be passed. I guess you could just use -

    SELECT count(*) FROM wp_gameUsers WHERE points > (SELECT points FROM wp_gameUsers where id =1)

    Subqueries are mysql 4.1 onwards, and WP only states mysql 4.0+, but your original solution selecting into @var_name is 4.1+ anyway.

Topic Closed

This topic has been closed to new replies.

About this Topic