我正在尝试使用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 **/
 }

07-24 09:49
查看更多