Running shortcode with variable that is modified

I think your “do_shortcode” is not parsing the variable.

Try with this code:

echo do_shortcode('[datatable id=30 var1="'.$idnr.'"]');

* Note the ‘ before and after the .