从MySQL结果数组中获取特定字段

时间:2009-12-06 17:39:39

标签: php mysql fetch

我正在尝试从查询的第一行中检索字段 media_file 。 我不知道该怎么做。我已多次尝试通过调用多维数组$pages[0]['media_file']来获取它,但没有成功。

我正在尝试将一个系列的第一张图像放大,然后追加另一个拇指。 这是我们正在讨论的页面: http://www.svarnet.it/index.php?/works/svarnet-dream/

这是代码:

function createExhibit()
{
 $OBJ =& get_instance();
 global $rs;

 $pages = $OBJ->db->fetchArray("SELECT * 
  FROM ".PX."media, ".PX."objects_prefs 
  WHERE media_ref_id = '$rs[id]' 
  AND obj_ref_type = 'exhibit' 
  AND obj_ref_type = media_obj_type 
  ORDER BY media_order ASC, media_id ASC");

 $s = "<div id='text-container'>\n";
 $s .= $rs['content'];
 $s .= "</div>\n";
 $s .= "\n<div class='cl'><!-- --></div>\n";

 if (!$pages) return $s;


 foreach ($pages as $height)
 {
  $height = getimagesize(DIRNAME . GIMGS . "/th-$height[media_file]");

  $find_smallest_height[] = $height[1];


 }

 sort($find_smallest_height, SORT_NUMERIC);
 rsort($find_smallest_height);
 $lowest = array_pop($find_smallest_height);

 $i = 1; $a = '';



 foreach ($pages as $go)
 {
  $a .= "\n<a class='group' rel='group' href='" . BASEURL . GIMGS . "/$go[media_file]' title='$go[media_title]'><imgXXX src='" . BASEURL . GIMGS . "/th-$go[media_file]' alt='$go[media_caption]' height='80px' /></a>\n";

  $i++;
 }

 // images


 $s .= "<div id='img-container'>\n";

 // //////////////// HERE I WANT TO INSERT THE FIRST IMAGE OF THE QUERY

 $s .= "<imgXXX src='" . BASEURL . GIMGS . $pages['media_file'] . "' alt='$pages[media_title]' />";

 // THEN APPEND THE OTHERS IN THUMB FORMAT

 $s .= $a;
 $s .= "</div>\n";

 return $s;
}

提前致谢!

1 个答案:

答案 0 :(得分:2)

您无法在双引号字符串中访问$height['media_file']变量。您将使用带花括号的complex syntax

"/th-{$height['media_file']}"
"/th-${height['media_file']}"

或者您使用string concatenation operator .

"/th-".$height['media_file']