【发布时间】:2015-08-08 00:01:54
【问题描述】:
从数据库表中获取图像的数据,在图像列中,我们有一个产品的 8 个不同尺寸的图像链接,每个图像链接都有其尺寸详细信息,例如:- 100x100、200x200、500x500 等。
所有图片都用逗号指定 喜欢:-
http://example.com/images/data/baby-care-100x100.jpg,
http://example.com/images/data/baby-care-200x200.jpg,
还有更多.....
从此所有图片链接中我需要找到 200x200 包含 img src 的链接
$productImage = array_key_exists('200x200', '$imageUrlStr')? $imageUrlStr['200x200']:'';
完整代码
$result = $mysqli->query("SELECT * FROM store where store= 'deals' AND bestOffer= '1' AND inStock= 'true' ");
while ($rows = $result->fetch_assoc()) {
$store = $rows["store"];
$productId = $rows["productId"];
$title = $rows["title"];
$description = $rows["description"];
$imageUrlStr = $rows["imageUrlStr"];
$productNewImage = array_key_exists('200x200', $imageUrlStr) ? $imageUrlStr['200x200'] : '';
【问题讨论】:
-
首先添加
$imageUrlStr的值。那么只能给出解决方案。谢谢。 -
我从数据库中获取它的价值,它的价值因每种产品而异,我该怎么办?
-
请显示更多代码。我们需要看看你是如何设置
$imageUrlStr。 -
打印出来。如果它是一个数组,那么
print_r($imageUrlStr)。否则回显$imageUrlStr。还是动态一个一个来? -
匹配它的字符串而不是数组,您需要使用
preg_match而不是array_keys_exits
标签: php mysql arrays image array-key-exists