好的,所以我取消了之前的尝试,现在我正在尝试禁用相关按钮,具体取决于当前pos的值和队列的长度。这是否更好?任何人都可以看到我出错的地方以及我应该如何修复它,以便根据正确的值实际禁用按钮?
<?php
if($_SESSION['currentpos'] < sizeof($_SESSION['queue'])){
$_SESSION['currentpos']++;
print("You have watched " . $_SESSION['currentpos'] . " out of " . count($_SESSION['queue']) . " clips.");
$temp = $_SESSION['currentpos'];
$query = "SELECT * FROM video WHERE video_id = :videoid";
try {
$stmt = $db->prepare($query);
$stmt->bindParam(':videoid', $_SESSION['queue'][$temp]['video_id']);
$result = $stmt->execute();
}
catch(PDOException $ex){ die("Failed to run query: " . $ex->getMessage()); }
if ($result) {
while( $row = $stmt->fetchObject() ) {
$_SESSION['videourl'] = $row->url;
}
}
unset($_SESSION['sessionid']);
?>
<div id="next">
<p> Thank you for completing the forms, please click the button below to begin the next clip</p>
<a class="btn btn-danger" id="nextbt" value="<?php echo $_SESSION['currentpos']; ?>" href="newviewvideo.php?url=<?php echo $_SESSION['videourl']; ?>" role="button">Start Next Video</a>
<a class="btn btn-danger" id="endbt" value="<?php sizeof($_SESSION['queue']); ?>" href="loginhomenew.php" role="button">Login Home</a>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
if ($('#nextbt').val() === $('#endbt').val()) {
{
$('#nextbt').prop('disabled', true);
$('#endbt').prop("disabled", false);
}
else
{
$('#endbt').prop("disabled", false);
}
});
答案 0 :(得分:0)
CSS
[{'Mw': 51, 'Price': 4889.37} , {'Mw': 58, 'Price': 5582.51} , {'Mw': 62, 'Price': 6533.27}],
PHP
#nextbt,#endbt{display:none;}
JS
if($type == 1){$bt = 'nextbt';}else{$bt = 'endbt';}
end of update
Just do your SQL and define a variable that says whether to show the End or Next div.
$type 1 = Next
document.getElementById('<?php$bt?>').display='block';";
The <?php
ob_start("ob_gzhandler");
header('Content-Type: text/html; charset=utf-8');
header('Connection: Keep-Alive');
header('Keep-Alive: timeout=5, max=100');
header('Cache-Control: max-age=60');
header('Vary: Accept-Encoding');
echo <<<EOT
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
</style>
</head><body><div id="page">
EOT;
ob_flush();
is used to get the output on it's way to the Browser while you do the SQL. The server will start sending the HTML to the Browser on the ob_start
Otherwise nothing will be transmitted until the end of the script.
The majority of the HTTP is prior to "First Byte"
To improve "Time to First Byte" (TFFB), you flush after the ob_flush()
and right before you need PHP to create the next HTML to be output.
Do not link to CSS. Just put the CSS in the <head>
, this will also help a lot in getting getting the Browser to "First Paint".
<head><style>