Media playback is unsupported on your device Media caption David Cameron taunts Ed Miliband on Sun and Murdoch links

The judge in the phone hacking trial has rebuked David Cameron for commenting on the conviction of Andy Coulson before the trial ended.

The prime minister has apologised for employing former News of the World editor Coulson as his media chief.

Mr Justice Saunders said his intervention was "unsatisfactory" and set a bad example to the media.

No 10 said the PM took the "best legal advice" before he spoke: widely taken as a reference to the Attorney General.

A spokesman for Attorney General Dominic Grieve later confirmed that the PM had consulted Mr Grieve "on his statement and his letter to the court before they were delivered".

The jury has been discharged after failing to reach verdicts on outstanding charges against Coulson.

Mr Justice Saunders will hear on Monday whether the Crown Prosecution Service wishes to launch a retrial.

In other developments:

Labour has asked a former senior civil servant to look at how Coulson was vetted before he started work at No 10, suggesting he did not receive the highest level of security clearance that was given to his predecessors in the role

Carole Middleton, the mother of the Duchess of Cambridge, was a victim of phone hacking, the BBC has learned

The sister of murdered schoolgirl Milly Dowler, Gemma, urges politicians to "keep their promises" to hacking victims by ensuring permanent changes to the way the press operates

The hacking trial has cost £1.745m so far, the Crown Prosecution Service said. The figures cover the period up to 31 May

Mr Cameron appointed Coulson as his director of communications in 2007, six months after he had quit as editor when the paper's royal editor Clive Goodman was jailed for phone hacking.

Coulson maintained that he knew nothing about hacking at the paper while he was its editor but was forced to quit in 2011 after allegations about it intensified.

The prime minister is facing questions about why Coulson did not receive the same level of vetting as his predecessors when he followed Mr Cameron into Downing Street in 2010.

Mr Cameron says Coulson's vetting was handled by his top official, Sir Jeremy Heywood and the "correct procedures" had been followed.

But Labour has asked a former senior civil servant, Sir David Normington, to look at why the former tabloid editor was not given the highest level of "developed vetting".

The BBC's Robert Peston said Sir Jeremy had not given Coulson the highest security clearance when he started work at Number 10 to save money but later allowed him access to top secret material because the senior civil servant thought he was a "good egg".

'Open season'

Shortly after Coulson was found guilty of conspiring to hack phones on Tuesday, Mr Cameron appeared on camera in Downing Street to issue an apology for employing him.

Image copyright Reuters Image caption A jury was unable to reach its verdict on the remaining charges against Coulson

At the time the jury had still to reach verdicts on separate charges of misconduct in public office against Coulson and Goodman.

Speaking in court, Mr Justice Saunders said the prime minister's actions had been regrettable.

"I consider that what has happened is unsatisfactory so far as justice and the rule of law are concerned.

"The press in court have been extremely responsible in their reporting of this case but when politicians regard it as open season, one cannot expect the press to remain silent."

A lawyer for Coulson said the prime minister's intervention was "ill-advised and premature" given the jury had to reach verdicts on other outstanding charges.

The BBC's Robert Peston on the vetting question

Image copyright PA

I know the answer to why Coulson was not given top level security vetting in 2010.

What happened was that Cabinet Secretary Sir Jeremy Heywood had decided that too many special advisers had access to the highest level of security clearance and wanted to reduce their number.

So he made a policy decision, without pressure from David Cameron, not to get Coulson cleared for access to such material. At the same time, Mr Cameron's chief of staff Ed Llewellyn was given the most vigorous degree of vetting, because of his foreign policy role.

Sir Jeremy simply felt it was inappropriate for large numbers of SPADs - as special advisers are known at Westminster - to have access to this material.

He subsequently decided Coulson was a good egg and could have access to this top secret sensitive material, even though he had not been cleared. So if anyone is going to be embarrassed by the failure to vet Coulson, and Labour's investigation into this, it will be Britain's top civil servant, Sir Jeremy Heywood.

He said No 10 had responded to the judge to make it clear that the prime minister's apology was in response to the verdict delivered in open court and was restricted to that issue.

The spokesman said there was widespread media coverage of the verdict and the prime minister had sought legal advice before issuing his statement.

'Some comfort'

Former justice secretary Ken Clarke told the BBC that the prime minister's statement was "unwise" but insisted that the trial had not been "prejudiced".

But the former Labour Lord Chancellor, Lord Falconer, said the laws on contempt of court, which are designed to guarantee fair trials, were "easily flouted" and should be reviewed.

Mr Cameron had "broken the rules", he suggested.

Image copyright Reuters Image caption Rebekah Brooks was cleared of all charges on Tuesday

It is not the first time that Mr Cameron has incurred the wrath of the judiciary for making public comments during a high-profile trial.

Last year, he gave a newspaper interview during the fraud trial of two of Nigella Lawson's former assistants in which he said he was a massive fan of the TV chef and was "on team Nigella".

The judge in that case told the jury to ignore the PM's "regrettable" comments, which he said could be construed as being "favourable" to Ms Lawson and therefore prejudicial, but refused requests to halt the trial. The two assistants were subsequently cleared of all charges.

The officer in charge of the police investigation which led to the phone-hacking trial said she hoped its outcome would provide "some comforts" to victims of intrusion.

Media playback is unsupported on your device Media caption Assistant Commissioner Cressida Dick: "Throughout the investigation we have done our best to follow the evidence, without fear or favour"

"This investigation has never been about an attack on press freedom but one to establish whether any criminal offences had been committed," Metropolitan Police Assistant Commissioner Cressida Dick said.

"Those found not guilty have been exonerated after a thorough police investigation and fair trial. It was right that the issues were aired publicly in a court of law."

Meanwhile, in Parliament, Labour leader Ed Miliband said Coulson had "brought disgrace to Downing Street" and the prime minister had been "negligent" in hiring him.

The prime minister, he suggested, had ignored a warning from the Deputy Prime Minister Nick Clegg about Coulson and paid scant attention to media reports about Coulson's alleged knowledge of phone-hacking.

"Today we know that for four years the prime minister's handpicked, closest adviser was a criminal and brought disgrace to Downing Street," he told MPs.

"We also know that the prime minister wilfully ignored multiple warnings about him."

Media playback is unsupported on your device Media caption Gemma Dowler: "I want to make sure that something good comes out of these terrible events"

He insisted that questions about Coulson's suitability for the job and his own role in his appointment had all been considered by the Leveson Inquiry into press standards.

"Leveson made no criticism of my conduct in this regard whatsoever," he said. He looked into all of the issues about the warnings I was given and the response I gave and he made no criticism of my conduct."

After 18 months looking into the culture and practices of the press, including its relationship with politicians, the Leveson Inquiry recommended a new body be set up to regulate the industry, backed up by legislation.

Labour have asked the Commissioner for Public Appointments, Sir David Normington, to look at why Coulson was not given top-level vetting

Mr Cameron told MPs that Labour was wrong to claim the vetting process would have "got to the bottom" of Coulson's past conduct as Leveson concluded that it would "not have involved a detailed investigation of phone hacking at News of the World".