-4

我有一个电影在线预订页面,用户可以在其中预订任何节目中的任何座位,但我有一个问题,即清除、预订按钮是固定的,我需要让它们移动到座位的最后一排下方。我使用了一个名为 $top 的变量来对行进行排序......现在我需要使 css 动态化

这是我的清除,保留按钮的CSS

#holder{
 height:<?php echo $top; ?>px;   //here's the problem, it doesnt work for me
 width:550px;
 background-color:white;
 border:0px solid #A4A4A4;
 margin-left:10px;
}

这是获取 $top 的 php 代码

<?php

$cols = 0;
$rows = 0;

$user_reserved_seats = array();

foreach( $seats as $seat )
{
$class = 'seat';

$seat_code = $seat['seats_code'];
$row = substr( $seat_code, 0, 1 ); //?

if( $row != $previous_row && $previous_row )
{
    ++$rows;
    $cols = 0;
}

$top = 35 * $rows;
$left = 35 * $cols;

if( $seat['reserved'] )
{
    $classToAdd = 'selectedSeat';

    if( $_GET['edit'] && $seat['member_id'] == $_SESSION['member_id'] )
    {
        $user_reserved_seats[] = $seat['seats_id'];

        $classToAdd = 'selectingSeat';
    }

    $class .= ' ' . $classToAdd;

}

echo "<li id=\"{$seat['seats_id']}\" class=\"{$class}\" style=\"top: {$top}px;left:{$left}px\">
        <a title=\"{$seat_code}\">{$seat_code}</a>
    </li>";

$previous_row = substr( $seat_code, 0, 1 ); //??
++$cols;
}
?>

谢谢

4

1 回答 1

3

这样做的唯一方法(不使用内联 css)是创建一个包含 css 的单独 php 文件。

使用一个名为style.php(或其他任何名称,只要它以 .php 结尾)的文件,其中包含:

<?php 
  header("Content-type: text/css");
  $top = '100'; 
?> 
height: <?php echo $top; ?>px;
width: 550px;
background-color: white;
border: 0px solid #A4A4A4;
margin-left: 10px;

包括这个文件:

<link href="style.php" rel="stylesheet" type="text/css">
于 2013-05-05T16:40:24.107 回答