[英]PHP MySQL multiple image URL fields array
In building a website for a friend the database has a row with 39 fields for images. 在为朋友建立网站时,数据库有一行,其中包含39个图像字段。 In the field is the name of the image (eg "my_image.jpg") not the image itself (BLOB).
在该字段中是图像的名称(例如“ my_image.jpg”),而不是图像本身(BLOB)。 ie: image_01, image_02, image_03 and so forth.
即:image_01,image_02,image_03等。
I have PHP generating the while loop and getting the information without problems. 我有PHP生成while循环并获取信息而没有问题。 I'm trying to get all the images into one array so I can display the pictures from that one row as a gallery.
我正在尝试将所有图像放入一个阵列,以便可以将这一行中的图像显示为图库。
I hope someone can offer me a way forward as I've tried without success. 我希望有人可以为我提供前进的道路,因为我尝试过没有成功。
from while loop: 从while循环:
$MEDIA_IMAGE_00 = $row["MEDIA_IMAGE_00"];
$MEDIA_IMAGE_01 = $row["MEDIA_IMAGE_01"];
$MEDIA_IMAGE_02 = $row["MEDIA_IMAGE_02"];
I need to echo out as 我需要回显为
["propimages/$MEDIA_IMAGE_00", "", "", "$MEDIA_IMAGE_TEXT_00"],
["propimages/$MEDIA_IMAGE_01", "", "", "$MEDIA_IMAGE_TEXT_01"],
["propimages/$MEDIA_IMAGE_02", "", "", "$MEDIA_IMAGE_TEXT_02"]
for them to display in a gallery. 让他们展示在图库中。
EDIT: 编辑:
while($row = mysql_fetch_array($sqlSearch)){
$propid = $row["propid"];
$MEDIA_IMAGE_00 = $row["MEDIA_IMAGE_00"];
$MEDIA_IMAGE_01 = $row["MEDIA_IMAGE_01"];
$MEDIA_IMAGE_02 = $row["MEDIA_IMAGE_02"];
$MEDIA_IMAGE_33 = $row["MEDIA_IMAGE_33"];
$MEDIA_IMAGE_34 = $row["MEDIA_IMAGE_34"];
$MEDIA_IMAGE_35 = $row["MEDIA_IMAGE_35"];
}
I'm assuming that $propid
is what identifies the row itself and that 'MEDIA_IMAGE_TEXT' is available in the same row: 我假设
$propid
标识行本身,并且'MEDIA_IMAGE_TEXT'在同一行中可用:
$properties = array();
while ($row = mysql_fetch_array($sqlSearch)) {
$propid = $row["propid"];
$images = array();
for ($i = 0; $i <= 35; ++$i) {
$imageId = "MEDIA_IMAGE_" . str_pad($i, 2, '0', STR_PAD_LEFT);
if ($row[$imageId]) {
$images[] = array(
$row[$imageId],
'',
'',
$row["MEDIA_IMAGE_TEXT_" . str_pad($i, 2, '0', STR_PAD_LEFT)],
);
}
}
$properties[] = array(
'id' => $propid,
'images' => $images,
);
echo json_encode($properties);
It generates a list of properties, each having an id and an array of images; 它生成一个属性列表,每个属性都有一个id和一个图像数组; each image comprises the location (I guess) and the title / description.
每个图像都包含位置(我想)和标题/描述。
Why don't you build an array of images in your while loop ? 为什么不在while循环中构建图像数组?
$images = array()
$i = 0;
While(...) {
$images[] = $row["MEDIA_IMAGE_0$i"];
$i++;
[...]
}
The you get an array that you ca use in a foreach and display your row(s). 您将获得一个可在foreach中使用的数组并显示您的行。 On the principle that should work, i think ;)
我认为应该根据应该起作用的原则;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.