PHP、MySQL:从数据库检索图像url字符串时出现问题
我在mysql数据库中存储了图像信息,如下所示PHP、MySQL:从数据库检索图像url字符串时出现问题,php,mysql,html,arrays,Php,Mysql,Html,Arrays,我在mysql数据库中存储了图像信息,如下所示 id, int(10), PRIMARY KEY title, varchar(255), utf8_unicode_ci url, varchar(255), utf8_unicode_ci example: http://www.blahblah.com/blahblah.png caption, varchar(255), utf8_unicode_ci width, int(10) height, int(10) entry_i
id, int(10), PRIMARY KEY
title, varchar(255), utf8_unicode_ci
url, varchar(255), utf8_unicode_ci example: http://www.blahblah.com/blahblah.png
caption, varchar(255), utf8_unicode_ci
width, int(10)
height, int(10)
entry_id, int(10), FOREIGN KEY
我正在尝试通过执行以下操作从所有图像中获取URL
<?php
include('connectdb.php');
include_once('functions.php');
include_once('class/class.Image.php');
// get all images for Entry
$imgArray = array();
$imgArray = getEntryImages( 3 );
$imgArray = getImageUrls ( $imgArray );
foreach( $imgArray as $img )
{
echo $img . ', ';
}
?>
如果有人能为我指出解决这个问题的任何方向,我将不胜感激,谢谢 您的问题是只能获取一次数组:
$row = mysql_fetch_array( $result );
因此,它在表的字段及其值上运行foreach
,而不是在整个结果集上
您需要获取数组,直到$row
为NULL
,如下所示:
while($image = mysql_fetch_array( $result )) {
$temp_image = new Image ( $image['id'], $image['title'], $image['url'],
$image['caption'], $image['width'], $image['height'],
$image['entry_id'] );
$imageArray[] = $temp_image;
}
您使用的图像库是什么?不确定我正在使用的图像库。我怎么才能知道呢?我只是在我的服务器上用database.doh中的“url”字符串指定的位置存储图像!我知道这很简单。我想我应该休息一会儿;(谢谢!
$row = mysql_fetch_array( $result );
while($image = mysql_fetch_array( $result )) {
$temp_image = new Image ( $image['id'], $image['title'], $image['url'],
$image['caption'], $image['width'], $image['height'],
$image['entry_id'] );
$imageArray[] = $temp_image;
}