我正在尝试使用 PHP 查询从我的 MSSQL 表列中获取图像名称。查询到的镜像名称放入<img>
标签中。如果该列为空,则应将空列设置为图像noimageishereforgbmtrailerserviceltd999.png
,这是一个空白.png
图像,并使链接不可单击。如果没有图像集,我这样做是为了基本上对用户隐藏图像,因此用户不会在图像应该所在的位置看到大 X。代码当前将列更改为正确noimageishereforgbmtrailerserviceltd999.png
,但不会更改其周围链接的 css 样式。这是我正在使用的PHP代码:
$job_posname = "SELECT * FROM new_trailers1 WHERE orderid = '$sn'";
$query=mssql_query( $job_posname, $connection);
$array=mssql_fetch_assoc($query);
$job_posname7=stripslashes($array['photo1']);
if ($job_posname7['photo1']===NULL || ctype_space($job_posname7['photo1'])){
$job_posname7 = "noimageishereforgbmtrailerserviceltd999.png";
echo "<script>document.getElementById('picca2').style.pointer-events='none';</script>";
echo "<script>document.getElementById('picca2').style.cursor='default';</script>";
} else {
$job_posname7=stripslashes($array['photo1']);
}
?>
<a id="picca2" href="unitimages/<? echo $job_posname7; ?>" onclick="swap(this); return false;"><img id="pica2" src="unitimages/<? echo $job_posname7; ?>" width=50 height=50></a>
感谢您的任何帮助。感谢所有帮助。
不能在所有列上默认noimageishereforgbmtrailerserviceltd999.png,如果数据库中存在图像,则只需更改它?我假设您正在动态生成列。
或者,如果设置了条件,只需在 PHP 变量上添加一个类。
在 css 中做一个.class,然后根据需要调用它。
例如
$job_posname = "SELECT * FROM new_trailers1 WHERE orderid = '$sn'";
$query=mssql_query( $job_posname, $connection);
$array=mssql_fetch_assoc($query);
$job_posname7=stripslashes($array['photo1']);
if ($job_posname7['photo1']===NULL || ctype_space($job_posname7['photo1'])){
$job_posname7 = "noimageishereforgbmtrailerserviceltd999.png";
echo "<script>document.getElementById('picca2').style.pointer-events='none';</script>";
echo "<script>document.getElementById('picca2').style.cursor='default';</script>";
$my_css_class_that_hides_image = "hide";
} else {
$job_posname7=stripslashes($array['photo1']);
}
?>
<a id="picca2" href="unitimages/<? echo $job_posname7; ?>" class="<? echo $my_css_class_that_hides_image; ?>" onclick="swap(this); return false;"><img id="pica2" src="unitimages/<? echo $job_posname7; ?>" width=50 height=50></a>
。并在样式表上定义它:
.hide{
/** Style here **/
}