我需要帮助将用户图像和用户名从sql编写为html我尝试了这些代码;
$query = mysql_query("SELECT * FROM tbl_images WHERE id<'".$id."'");
$row = mysql_fetch_array($query) or die();
$query = mysql_query("SELECT username FROM Users WHERE id<'".$id."'");
echo '<table>';
while($rowtwo = mysql_fetch_array($query)){
echo '<tr>
<td><img height="115" width="115" src="data:image/jpeg;base64,' . base64_encode( $row['image'] ) . '"/></td>
<td><font size="2" face="Lucida Sans Unicode" color=#EBEBEB>' .$rowtwo['username'].'</td>
</tr>';}
echo '</table>';
答案 0 :(得分:0)
你应该尝试对用户名和图像进行连接查询,这样你只需要使用一个查询和一个mysql_fetch_array()
尝试这样:
$query = mysql_query("SELECT i.image, u.username FROM tbl_images i JOIN Users u ON u.id=i.id WHERE u.id<'".$id."'");
if(!$query) die("MYSQL: ".mysql_error());
echo '<table>';
while($row = mysql_fetch_array($query)){
echo '<tr>
<td><img height="115" width="115" src="data:image/jpeg;base64,' . base64_encode( $row['image'] ) . '"/></td>
<td><font size="2" face="Lucida Sans Unicode" color=#EBEBEB>' .$row['username'].'</td>
</tr>';}
echo '</table>';
但你的base64_encode是否正确?我认为它应该是解码???