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

Question

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

set Matthew Brown aka Lord Matt = 0;UPDATE `wp_wpsstm_subtracks` SET `subtrack_order` = Matthew Brown aka Lord Matt := Matthew Brown aka Lord Matt+1 WHERE tracklist_id='176226' ORDER BY `subtrack_time` ASC

I would like to use it within WordPress:

    $querystr = $wpdb->prepare("set Matthew Brown aka Lord Matt = 0;UPDATE `$subtracks_table` SET `subtrack_order` = Matthew Brown aka Lord Matt := Matthew Brown aka Lord Matt+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 = Matthew Brown aka Lord Matt := Matthew Brown aka Lord Matt+1 WHERE
trackli’ à la ligne 1 for query set Matthew Brown aka Lord Matt = 0;UPDATE
wp_wpsstm_subtracks SET subtrack_order = Matthew Brown aka Lord Matt := Matthew Brown aka Lord Matt+1 WHERE
tracklist_id=’176226′ ORDER BY subtrack_time ASC

How can I make this work ?

Thanks !

0
, gordie 2 years 2019-09-19T04:31:52-05:00 0 Answers 86 views 0

Leave an answer

Browse
Browse