Javascript resize on every image load
<p>I've got this code:</p>

<pre><code>while ($row = mysql_fetch_assoc($result1)) {
echo "
&lt;a href='#'id='VV".$row['id']."'&gt;
&lt;p&gt;".$row['title']."&lt;/p&gt;
&lt;p&gt;".$row['date']."&lt;/p&gt;
&lt;img onload='scale()' id='II".$row['id']."' src='../res/videos/img/".$row['img']."'/&gt;
&lt;/a&gt;
&lt;script type='text/javascript'&gt;
function scale(){
    var image = document.getElementById('II".$row['id']."');
    var width = image.width;
    var height = image.height;
    if (width &gt; 150) {
    image.style.width = '150px';
    image.style.height = 'auto';
    }
    width = image.width;
    height = image.height;
    if (height &gt; 80) {
    image.style.height = '80px';
    image.style.width = 'auto';
    }
    width = image.width;
    height = image.height;
}
VV".$row['id'].".onclick = function() {
var Result = '".$row['id']."';
location.href='loged.php?Result=' + Result;
     }
&lt;/script&gt;
";
}?&gt;
</code></pre>

<p>I want the resize function be called on every image loaded, but it is called when the last image is loaded, and only the last image takes effect. What should i change?</p>
