从mysql中检索一批图像

时间:2012-10-24 01:21:29

标签: php mysql

我正在尝试从包含表格中的文件名的列中显示8张图片,表格是正确的,字段interest_idinterest_pic(存储文件名的位置)是正确的。

$interest_image_query = mysql_query("SELECT interest_pic FROM interest_pictures WHERE interest_id='$i_id'");
$i = 0;
while($interest_display_image = mysql_fetch_array($interest_image_query) && $i < 8){
  echo '<td><img src ="/uploads/images/interestpics/'.$interest_display_image['interest_pic'].'" width=60px height=60px /></td>'; 
  $i++;
}

输出似乎显示文件夹位置但没有文件名。在这种情况下$i_id = 20,并且已经过验证并正常工作。感谢任何帮助,谢谢!

2 个答案:

答案 0 :(得分:0)

发现&& $i < 8导致$interest_display_image设置为布尔“true”

替换为if($i < 8){}

答案 1 :(得分:0)

你确定你运行mysql_select_db()来选择合适的表吗?这对我有用。

我还在查询中添加了一个LIMIT,只返回8个结果,并在img标记后用括号中的文件名回显,以确认它正在拉动文件名。

$link = mysql_connect('localhost', 'user', 'password');
mysql_select_db("tablename");

$i_id = 1;
$interest_image_query = mysql_query("SELECT interest_pic FROM interest_pictures WHERE interest_id='$i_id' LIMIT 8");

while($interest_display_image = mysql_fetch_array($interest_image_query, MYSQL_BOTH)){
    echo '<td><img src ="/uploads/images/interestpics/'.$interest_display_image['interest_pic'].'" width=60px height=60px /> (' . $interest_display_image['interest_pic'] . ')</td>';
}