代码如下:<?php
//header("content-type: image/png");
include("config.php");
$s1 = "SELECT * FROM question WHERE t=0";
$result = mysql_query($s1);
$i = 0;
while($row=mysql_fetch_array($result))
{
$id = $row["id"];
$content0 = $row["content"];
$s2 = "SELECT * FROM question WHERE t='$id' ";
$result1 = mysql_query($s2);
echo "<table>";
echo "<tr><td colspan='2' align='center'>".$content0."</td></tr>";
while($rows=mysql_fetch_array($result1))
{
$content = $rows["content"];
$num = $rows["num"] * 10;
$im = imagecreate($num,20);
$black = imagecolorallocate($im,rand(0,254),rand(0,255),rand(0,255));
$name = $i;
imagepng($im,"E:\apache\htdocs\image\$name.png");
echo "<td>".$content."</td>";
echo "<td><img src=image\$name.png></td>";
     echo "<td>".($num/10)."</td>
    </tr>";
imagedestroy($im);
$i ++;
}
echo "</table>";
}
?>发现把imagecreate放在循环里 总是会出错Warning: imagecreate() [function.imagecreate]: Invalid image dimensions 而且输出的图片都是一张图片  是什么原因呢

解决方案 »

  1.   

     Warning: imagecreate() [function.imagecreate]: Invalid image dimensions : 无效的图片尺寸
    说明 $num = $rows["num"] * 10; 这儿的 $rows["num"]可能是个空字符串值。至于为什么是空值,就看你的表设计了
      

  2.   

    这个是一个简单的投票系统  表中有一个标记t 和 id  t为0 标示 是投票的问题 投票选项的t值为 投票问题的id值
     id int(6) not null primary key auto_increment,
     t int(6) not null default 0,
     content varchar(400) not null default ' ',
     num int(6) not null default 0
      

  3.   

     Invalid image dimensions  无效的图像尺寸
    $num = $rows["num"] * 10; // $rows["num"]有可能 <= 0
    $im = imagecreate($num,20);你有 echo "<td><img src=image\$name.png></td>";
    所以只要看一下浏览器都得到了什么就知道了
      

  4.   

    我是要你在浏览器上 右键——查看网页源代码
    观察那些由 echo "<td><img src=image\$name.png></td>"; 产生的html标记
      

  5.   

    被你忽悠了
    echo "<td><img src=image\$name.png></td>";
    只能得到 <td><img src=image\$name.png></td> 这样的结果!
    你需要
    echo "<td><img src=image/$name.png></td>";才能得到
    <td><img src=image/1.png></td>
    <td><img src=image/2.png></td>
    <td><img src=image/3.png></td>