Skip to main content
edited title
Link
gordie
  • 492
  • 4
  • 19

use mysql variable in a $wpdb->query to reindex a column?

Source Link
gordie
  • 492
  • 4
  • 19

use mysql variable in a $wpdb->query?

I have this MySQL query, which do work in PHPMyAdmin:

set @ROW = 0;UPDATE `wp_wpsstm_subtracks` SET `subtrack_order` = @ROW := @ROW+1 WHERE tracklist_id='176226' ORDER BY `subtrack_time` ASC

I would like to use it within Wordpress:

    $querystr = $wpdb->prepare("set @ROW = 0;UPDATE `$subtracks_table` SET `subtrack_order` = @ROW := @ROW+1 WHERE tracklist_id='%d' ORDER BY `subtrack_time` ASC", $this->post_id );
    return $wpdb->query($querystr);

But it fires a syntax error:

WordPress database error Erreur de syntaxe près de 'UPDATE wp_wpsstm_subtracks SET subtrack_order = @ROW := @ROW+1 WHERE trackli' à la ligne 1 for query set @ROW = 0;UPDATE wp_wpsstm_subtracks SET subtrack_order = @ROW := @ROW+1 WHERE tracklist_id='176226' ORDER BY subtrack_time ASC

How can I make this work ?

Thanks !