Home  >  Article  >  Backend Development  >  遇到麻烦 求高手解决办法

遇到麻烦 求高手解决办法

WBOY
WBOYOriginal
2016-06-13 10:21:50966browse

遇到麻烦 求高手
[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)){
?>
 


  名字: | 大小: 上传时间:
 
  遇到麻烦 求高手解决办法
  产品说明:
   
 
  }
?
我这样调用图片是出来了 但是图片失真了 我应该如果处理呀?怎么样才能才能不要图片失真?

------解决方案--------------------
width="300" height="200" 
你限制了大小,当然会失真。
------解决方案--------------------
写了个JS处理方法,把这段代码放到head标签中试试。(没仔细调试,可能还存在问题,明天再看看)
HTML code
<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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn