Home >Backend Development >PHP Tutorial > 遇到麻烦 求高手解决办法
遇到麻烦 求高手
[code=PHP][/code]
include("conn.php");
if(isset($_GET['page'])){
$page=$_GET['page'];
}else{
$page=1;
}
?>
if($page)
$page_size=4;
$query="select * from chanpin";
$yue=mysql_query($query);
$message_count=mysql_num_rows($yue);
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$query="select * from chanpin where id order by id desc limit $offset, $page_size";
$arr=mysql_query($query,$conn);?>
while($result=mysql_fetch_array($arr)){
?>
<script type="text/javascript"> function getImgSize(img) { var result = {}; var w = img.width; var h = img.height; if (w > 300) { if (h <= 200) { result.width = 300; result.height = Math.ceil(parseInt(h) * 200 / 300); } else { if (w / h == 1.5) { result.width = 300; result.height = 200; } else if (w / h > 1.5) { result.width = 300; result.height = 0; } else { result.width = 0; result.height = 200; } } } else { if (h <= 200) { result.width = w; result.height = h; } else { result.height = 200; result.width = Math.ceil(parseInt(w) * 200 / h); } } return result; } window.onload = function() { var obj = document.getElementsByTagName('table')[0].getElementsByTagName('img'); for (var i = 0; i < obj.length; i ++) { var wh = getImgSize(obj[i]); if (wh.width > 0) obj[i].style.width = wh.width + 'px'; if (wh.height > 0) obj[i].style.width = wh.height + 'px'; } } </script> <br><font color="#e78608">------解决方案--------------------</font><br>只需对 img 单边控制就能保持原来的比例<br><br>list($width, $height) = getimagesize($result['lujing']);//可能需对$result['lujing']中的路径做适当调整<br><br>...<img src="<?php%20echo%20%24result%5B'lujing'%5D;%20?>" echo alt=" 遇到麻烦 求高手解决办法 " >$height*1.5 ? 'width="300"' : ' style="max-width:90%" ?> />....<br><br>使用 js 也是一样<br><br> <br><font color="#e78608">------解决方案--------------------</font><br><?php <br />$a_size = getimagesize('1.jpg');<br>print_r($a_size);<br>?><br>利用该函数得到的结果去对控制图片的大小 <br><font color="#e78608">------解决方案--------------------</font><br>你把PHP生成的表格代码发上来啊。 <div class="clear"> </div>