我正在创建一个时事通讯,我希望将name
插入的数据库图像显示到我的数据库中。当我尝试显示图像时,但不显示图像。
$date = $_POST['date'];
$qry_banner = "INSERT INTO `banner_tbl`(`banner_img`, `date`) VALUES ('$img_banner','$date')";
$res_banner = mysql_query($qry_banner);
$banner_tbl_id = mysql_insert_id();
$sec_id = $_POST['sectionID'];
$sec_active_image = $_POST['activeimage'];
$sec_title = $_POST['section_title'];
$total_sec = count($sec_id);
for($i=0;$i<$total_sec;$i++)
{
$qry_section1 = "INSERT INTO `section_lt_tbl`(`banner_id`, `sectionID`, `activeimage`, `sectiontitle`) VALUES
('$banner_tbl_id','$sec_id[$i]','$sec_active_image[$i]','$sec_title[$i]')";
$nav_1_img = mysql_query("SELECT `activeimage` FROM `section_lt_tbl` WHERE sectionID = '1' limit 1");
$nav_2_img = mysql_query("SELECT `activeimage` FROM `section_lt_tbl` WHERE sectionID = '2' limit 1");
$nav_3_img = mysql_query("SELECT `activeimage` FROM `section_lt_tbl` WHERE sectionID = '3' limit 1");
$nav_4_img = mysql_query("SELECT `activeimage` FROM `section_lt_tbl` WHERE sectionID = '4' limit 1");
$res_section1 = mysql_query($qry_section1);
$sec_tbl_id1 = mysql_insert_id();
$section_generated_id[] = $sec_tbl_id1;
}
$nav_1_img_val = mysql_fetch_assoc ($nav_1_img);
$nav_2_img_val = mysql_fetch_assoc ($nav_2_img);
$nav_3_img_val = mysql_fetch_assoc ($nav_3_img);
$nav_4_img_val = mysql_fetch_assoc ($nav_4_img);
下面是我的html代码,我正在尝试显示图像:
<td bgcolor="#dbdbdb" align="center"><table border="0" cellpadding="0" cellspacing="0" width="550" align="center">
<tr>
<td width="25%"><a href="#featuredstartup"><img src="uploads/<?php echo $nav_1_img_val ?>_blue.jpg" width="125px" height="134px" />
</a></td>
<td width="25%"><a href="#healthcaredeals"><img src="uploads/<?php echo $nav_2_img_val ?>_grey.jpg" width="125px" height="134px" /></a></td>
<td width="25%"><a href="#healthcarenews"><img src="uploads/<?php echo $nav_3_img_val ?>_grey.jpg" width="125px" height="134px" /></a></td>
<td width="25%"><a href="#healthcaremarkets"><img src="uploads/<?php echo $nav_4_img_val ?>_grey.jpg" width="125px" height="134px" /></a></td>
</tr>
</table>
</td>
答案 0 :(得分:2)
将img src标记修改为以下内容。
<img src="uploads/<?php echo $nav_1_img_val['activeimage'] ?>_blue.jpg" width="125px" height="134px" />
mysql_fetch_assoc()将返回一个关联数组,您必须获取相应的键值。
答案 1 :(得分:1)
您必须使用$nav_1_img_val['activeimage']
而不是$nav_1_img_val
,因为mysql_fetch_assoc正在返回一个数组。
答案 2 :(得分:1)
mysql_fetch_assoc
返回一个关联数组。
您需要使用名称来访问数组的值 列是关键。
$nav_1_img_result = mysql_fetch_assoc ($nav_1_img);
$nav_1_img_val = $nav_1_img_result['activeimage'];