while ループから出力配列を作成し、その中の値の数を数えます。count(array) を使用して rand() で乱数を計算し、インデックスが乱数と一致する場合の if ステートメントを使用して、出力配列を反復処理します。
<?php
mysql_connect("localhost","root","");
mysql_select_db("bravo");
$res=mysql_query("select * from coisas");
?>
<div>
<?php
$output_array = array();
while ($row=mysql_fetch_array($res)) {
$output_array[] = "<img src=\"{$row['imagem']}\">";
}
//If you want the image to appear closer to middle, use fractions of $output_array
//EG: rand(count($output_array)/3, count($output_array)*2/3));
$rand_key = rand(0, count($output_array)-1);
foreach ($output_array as $key => $img) {
if ($key == $rand_key) {
//echo your adsense code
}
echo $img;
}
?>
</div>