我有一个joomla数据库,其中包含一个具有多个图像路径的字段。我想分离这些路径并使用json_decode读取它们。但是当我尝试我的代码时,图像源是空的(我希望显示路径)
我如何获取数据并使用json_decode:
$content = "SELECT * FROM `snm_content` WHERE catid = 13";
$contentcon = $conn->query($content);
$contentcr = array();
while ($contentcr[] = $contentcon->fetch_array());
$image = json_decode($content['images'], true);
我在foreach中得到以下内容:
<img src="'.$image['image_intro'].'" alt="" class="company_logo">
我在img src中没有得到任何输出。那是为什么?
如果这是相关的话,这就是我开始foreach的方式:
foreach($contentcr as $content)
{
$ contentcr的输出:
" [6]=> string(1) "1" ["state"]=> string(1) "1" [7]=> string(2) "13" ["catid"]=> string(2) "13" [8]=> string(19) "2015-11-20 08:56:29" ["created"]=> string(19) "2015-11-20 08:56:29" [9]=> string(3) "361" ["created_by"]=> string(3) "361" [10]=> string(0) "" ["created_by_alias"]=> string(0) "" [11]=> string(19) "2015-11-30 11:00:10" ["modified"]=> string(19) "2015-11-30 11:00:10" [12]=> string(3) "361" ["modified_by"]=> string(3) "361" [13]=> string(3) "361" ["checked_out"]=> string(3) "361" [14]=> string(19) "2015-12-02 10:49:59" ["checked_out_time"]=> string(19) "2015-12-02 10:49:59" [15]=> string(19) "2015-11-20 08:56:29" ["publish_up"]=> string(19) "2015-11-20 08:56:29" [16]=> string(19) "0000-00-00 00:00:00" ["publish_down"]=> string(19) "0000-00-00 00:00:00" [17]=> string(209) "{"image_intro":"images\/mobieleairco\/Airco_blog.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}" ["images"]=> string(209) "{"image_intro":"images\/mobieleairco\/Airco_blog.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}" [18]=> string(121) "{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}" ["urls"]=> string(121) "{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}" [19]=> string(593) "{"show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_layout":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}" ["attribs"]=> string(593) "{"show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_layout":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}" [20]=> string(2) "14" ["version"]=> string(2) "14" [21]=> string(1) "3" ["ordering"]=> string(1) "3" [22]=> string(22) "€ 50 (vanaf 2 weken)" ["metakey"]=> string(22) "€ 50 (vanaf 2 weken)" [23]=> string(5) "Slang" ["metadesc"]=> string(5) "Slang" [24]=> string(1) "1" ["access"]=> string(1) "1" [25]=> string(1) "0" ["hits"]=> string(1) "0" [26]=> string(53) "{"robots":"","author":"","rights":"","xreference":""}" ["metadata"]=> string(53) "{"robots":"","author":"","rights":"","xreference":""}" [27]=> string(1) "0" ["featured"]=> string(1) "0" [28]=> string(1) "*" ["language"]=> string(1) "*" [29]=> string(0) "" ["xreference"]=> string(0) "" } [1]=> array(60) { [0]=> string(2) "10" ["id"]=> string(2) "10" [1]=> string(2) "69" ["asset_id"]=> string(2) "69" [2]=> string(16) "Aelia 12 (AL-12)" ["title"]=> string(16) "Aelia 12 (AL-12)" [3]=> string(14) "aelia-12-al-12" ["alias"]=> string(14) "aelia-12-al-12" [4]=> string(297) "
答案 0 :(得分:0)
您的变量名称令人困惑,但您在sql字符串上调用json_decode
的答案,而不是行:
$sql = "SELECT * FROM `snm_content` WHERE catid = 13";
$result = $conn->query($content);
while ($row = $result->fetch_array()){
$image = json_decode($row['images'], true);
echo '<img src="'.$image['image_intro'].'" alt="" class="company_logo">';
}