• 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?

Viewing 1 replies (of 1 total)
  • 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.

Viewing 1 replies (of 1 total)
  • The topic ‘MySql MultiLine Query doesn’t work?’ is closed to new replies.