由于“原始数据”,PHP脚本无法正常工作

时间:2012-04-17 19:42:58

标签: php html compression

我有以下php代码:

<?php
include "../config.php"; //includes the connection data
$query="SELECT userinvites.user_id, COUNT( * ) AS user_count, users.fname, users.lname,        users.image
FROM userinvites
INNER JOIN users ON userinvites.user_id = users.user_id
GROUP BY user_id
ORDER BY COUNT( * ) DESC 
LIMIT 0 , 10"; //basic query that gets the data for leaderboard 
$result = mysql_query($query) or die(mysql_error());
echo '<table width="285" border="0" cellpadding="0" cellspacing="0">' ;
while($row = mysql_fetch_array($result)){
    //echo "-". $row['image']. " - ". $row['fname']. " - ". $row['lname']. " - ".      $row['user_count'];
    //echo "<br />";
    echo '<tr>';
    echo "<td height='40'> ". $row['image'].  "</td>";
    echo "<td>". $row['fname']. " ". $row['lname']. "</td>";
    echo "<td>" . $row['user_count']. "</td>";
    echo "</tr>";
}
echo '</table>';
?>

当我将此代码单独放在.php页面中时,它可以正常工作。当我尝试在另一个.php页面中导入此脚本时,我收到一条消息,说明数据压缩是错误的。对于发生了什么的任何想法?

1 个答案:

答案 0 :(得分:0)

好吧,如果它是原始图像数据,那么这应该适用于while循环(将image/gif更改为适当的类型):

while($row = mysql_fetch_array($result)){
  echo '<tr>'
    .'<td height="40">'
      .'<img src="data:image/gif;base64,' . base64_encode($row['image']) . '">'
    .'</td>'
    .'<td>' . htmlspecialchars($row['fname'] . ' ' . $row['lname']) . '</td>'
    .'<td>' . htmlspecialchars($row['user_count']) . '</td>'
    .'</tr>';

}