scriptNext() is working!!
However, it seems the variable order is significant after all. I now have
$where = "$selection AND branch.crf_type_id = '$crf_type_id'";
The difference since the very first post is the order of the selection criteria variable and $selection. It fails if I put them the other way round. I had also changed a relationship so that the table qualifier is different, but I don't think that was significant. I'd accidentally had an additional 'AND' when I did the previous post so that solves the different versions of the same syntax error. Sorry about that one.