Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP将SQL列分解为变量_Php_Mysql - Fatal编程技术网

使用PHP将SQL列分解为变量

使用PHP将SQL列分解为变量,php,mysql,Php,Mysql,嘿,伙计们,我在尝试让我的SQL列成为PHP中的变量时遇到了一些麻烦 因此,我的SQL行包含图像URL,其格式如下: http://www.website.com/image.jpg,http://www.website.com/image2.jpg,http://www.website.com/image3.jpg 现在我需要显示行中的第一个URL 我有一行简短的代码: file = '.(explode(',', $cardata["PictureRefs"])[0]).'; 我基本上是

嘿,伙计们,我在尝试让我的SQL列成为PHP中的变量时遇到了一些麻烦

因此,我的SQL行包含图像URL,其格式如下:

http://www.website.com/image.jpg,http://www.website.com/image2.jpg,http://www.website.com/image3.jpg
现在我需要显示行中的第一个URL

我有一行简短的代码:

file = '.(explode(',', $cardata["PictureRefs"])[0]).';
我基本上是想给变量一个值:

$file = "http://www.website.com/image.jpg"
我目前的代码显然是错误的,但我觉得我必须非常接近。我如何才能做到这一点?

试试这个:

$file = explode(',',$cardata);
$img = $file[0];

您的简写是正确的,但是字符串封装并不是必需的

$file = explode(',', $cardata['pictureRefs'])[0]; // first image SRC
然后你可以像这样利用它:

echo '<img src="'.$file.'"/>';
echo';
没问题


$file=explode(“,”,$cardata)[0]

不需要引入那个额外的变量。我刚刚尝试了这个,我得到了这个语法错误:
解析错误:语法错误,意外的“$cardata”(T_变量)出现在…
知道为什么吗?@PeterHardy在“
”之后漏掉了一个逗号,
”。请再查一下,对不起。