A witness shall not be allowed compensation for his attendance in more than one case or on more than one side of the same case at the same time, but he may elect in which of several cases and on which side of a case in which he is summoned for both sides, to claim his attendance. The party who pays a witness shall be entitled to recover of the parties in other cases who were liable to such witness a just proportion of the amount to which the witness was entitled for his attendance as the witness of such parties during the same time; and a person who is compelled to attend court on other business shall not be paid as a witness.