我的页面顶部有一些 PHP,可以从数据库中读取默认的 css 值:
$query = "
SELECT
width,
height,
fontFamily,
fontSize,
color,
backgroundColor,
lineHeight,
marginTop,
marginLeft,
textAlign,
borderColor,
borderWidth,
boxShadow,
borderRadius,
last_url_published,
color1,
color2,
color3,
color4,
color5,
color6
FROM
users
WHERE
id = :id
";
$query_params = array (
':id' => $_SESSION['user']['id']
);
// echo("<br />index.php: query for defaults is: $query");
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("index.php line " . __LINE__ . ". Failed to read defaults from users table: " . $ex->getMessage());
}
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$row = $stmt->fetch();
extract($row); // produces $width, etc.
// echo("<br />killing time here");
在我的 HTML 中
<body>
.cell_db {
width: <?=$width?>;
height: <?=$height?>;
background-color: <?=$backgroundColor?>;
border-color: <?=$borderColor?>;
border-width: <?=$borderWidth?>;
border-radius:<?=$borderRadius?>;
box-shadow:<?=$boxShadow?>
}
我看到的是,如果我不把
echo("<br />killing time here");
在 extract($row) 语句之后的行中,css 值 - 例如 width :不被分配。例如,extract($row) 中的 $width 值在 css 行被评估时显然还没有准备好php。但是从 echo 语句中插入延迟提供了所需的时间。有谁知道这里发生了什么以及我如何才能做到这一点?
谢谢
附录:
下面的人要求查看从 PHP 到 HTML 的所有代码,所以这里是:
<?php
//phpinfo();
ini_set('display_errors', 1);
error_reporting(E_ALL);
include ('functions.php'); // so we can call our showarray()
// First we execute our common code to connect to the database and start the session
require("common.php");
// showarray($_SESSION, "index.php, line " . __LINE__ . " SESSION Data:");
$_SESSION['landingPage'] = $_SERVER['PHP_SELF']; // login will redirect to here, either index.php or indexX.php, after password matches
// At the top of the page we check to see whether the user is logged in or not.
if(empty($_SESSION['user']))
{
// If they are not, we redirect them to the login page.
header("Location: login.php");
// Remember that this die statement is absolutely critical. Without it,
// people can view your members-only content without logging in.
die("Redirecting to login.php");
}
// get box default style for this user from the database
// update default styles
$query = "
SELECT
width,
height,
fontFamily,
fontSize,
color,
backgroundColor,
lineHeight,
marginTop,
marginLeft,
textAlign,
borderColor,
borderWidth,
boxShadow,
borderRadius,
last_url_published,
color1,
color2,
color3,
color4,
color5,
color6
FROM
users
WHERE
id = :id
";
$query_params = array (
':id' => $_SESSION['user']['id']
);
// echo("<br />index.php: query for defaults is: $query");
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("index.php line " . __LINE__ . ". Failed to read defaults from users table: " . $ex->getMessage());
}
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$row = $stmt->fetch();
extract($row); // produces $width, etc.
sleep(1);
// echo("<br />killing time here");
// open_color picker - in color.js
// open color panel - in color.js
?>
<!doctype html>
<!-- HTML5 -->
<html>
<head>
<meta charset="utf-8">
<title>MyWebsheet</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script src="js/GLOBALS.js"></script> <!-- Load these before editbox.js and color.js so they can see them when compiled -->
<script src="js/weebly_editbox.js"></script>
<script src="js/color.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript" src="js/jquery.Jcrop.js"></script>
<script src="http://www.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?key= Fmjtd%7Cluub2h0z21%2C7a%3Do5-9utaqr"></script>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<!-- <link rel="stylesheet" type="text/css" href="CSS/reset.css" /> -->
<link rel="stylesheet" type="text/css" href="CSS/jquery.Jcrop.css" />
<!-- ***************************************************************************************************** -->
<!-- STYLES -->
<!-- ***************************************************************************************************** -->
<style type="text/css">
/* style top */
body { /* style wings wings style body color*/
height:4000px;
background-color:<?php echo ($_SERVER['PHP_SELF'] == '/indexX.php'? 'white' : '#165E3D')?>;
background-color:#fff;
background-color:#d44; /* change to make sure a new index.php is being uploaded */
margin:0;
padding:0px; /* keeps everything 10px away from walls */
}
/*
a {
cursor : pointer;
} */
p {
/* margin-top: 10px; */
}
#wrapper {
width:1024px;
height:800px;
position: absolute;
left:50%; /* puts left edge of wrapper at mid-point of viewport */
margin-left: -512px; /* shifts wrapper left half of its width */
background-color:transparent;
}
.cell_base {
position:absolute;
z-index:3;
border-style: solid;
display:none;
}
.cell_db {
width: <?=$row['width']?>;
height: <?=$row['height']?>;
background-color: <?=$backgroundColor?>;
border-color: <?=$borderColor?>;
border-width: <?=$borderWidth?>;
border-radius:<?=$borderRadius?>;
box-shadow:<?=$boxShadow?>
}
.cellContent_db {
font-family: <?=$fontFamily?> ;
margin-top: <?=$marginTop?>;
margin-left: <?=$marginLeft?>;
font-size: <?=$fontSize?>;
color: <?=$color?>;
line-height: <?=$lineHeight?>;
text-align: <?=$textAlign?>;
}