我正在使用 turn.js 制作一本书。div
“死亡笔记”中的每一个都div
成为一个新的页面。
<div id="deathnote"> //starts book
<div style="background-image:url(images/coverpage.jpg);"></div> //creates new page
<div style="background-image:url(images/paper.jpg);"></div> //creates new page
<div style="background-image:url(images/paper.jpg);"></div> //creates new page
</div> //ends book
我正在做的是尝试将 3 个“内容”(内容是名称和死因)divs
放到 1 个页面上,然后生成一个新页面。
所以这就是我想要的:
<div id="deathnote"> //starts book
<div style="background-image:url(images/coverpage.jpg);"></div> //creates new page
<div style="background-image:url(images/paper.jpg);"></div> //creates new page
<div style="background-image:url(images/paper.jpg);"> //creates new page but leaves it open
<div> CONTENT </div>
<div> CONTENT </div>
<div> CONTENT </div>
</div> //ends the page
</div> //ends book
看起来很简单,但是内容是来自 MySQL 数据库的数据,所以我必须在使用 PHP 时回应它。这是我到目前为止所拥有的
<div id="deathnote">
<div style="background-image:url(images/coverpage.jpg);"></div>
<div style="background-image:url(images/paper.jpg);"></div>
<div style="background-image:url(images/paper.jpg);"></div>
<div style="background-image:url(images/paper.jpg);"></div>
<div style="background-image:url(images/paper.jpg);"></div>
<div style="background-image:url(images/paper.jpg);"></div>
<?php
$pagecount = 0;
$db = new mysqli('localhost', 'username', 'passw', 'DB');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = <<<SQL
SELECT *
FROM `TABLE`
SQL;
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
//IGNORE ALL OF THE GARBAGE ABOVE. IT IS SIMPLE CONNECTING SCRIPT THAT I KNOW WORKS
//THE METHOD I AM HAVING TROUBLE WITH IS BELOW
$pagecount = 0;
while($row = $result->fetch_assoc()){ //GETS THE VALUE (and makes sure it isn't nothing
echo '<div style="background-image:url(images/paper.jpg);">'; //THIS OPENS A NEW PAGE
while ($pagecount !== 3) { //KEEPS COUNT OF HOW MUCH CONTENT DIVS IS ON THE PAGE
while($row = $result->fetch_assoc()){
//START A CONTENT DIV
echo '<div class="content"><div class="name">' . $row['victim'] . '</div><div class="cod">' . $row['cod'] . '</div></div>';
//END A CONTENT DIV
$pagecount++; //UP THE PAGE COUNT
}
}
$pagecount=0; //PUT IT BACK TO 0
echo '</div>'; //END PAGE
}
$db->close();
?>
<div style="background-image:url(images/backpage.jpg);"></div> //BACK PAGE
</div>
目前我似乎正在导致无限循环,因此页面不会加载。问题存在于while
循环中。
任何帮助是极大的赞赏。提前谢谢各位。:)