我创建了一个php页面,我希望每当我刷新页面时,它应该洗牌,而在该数据中,我希望每当我点击数据时,它应该重定向到一个新页面,在该页面中,应该显示该数据,为此,我使用了会话来存储它。
home.php
<?php
$con = new mysqli("localhost","root","","writersplanet");
$sql = "SELECT * FROM books ORDER BY RAND()";
$execute = mysqli_query($con,$sql);
while ($row = mysqli_fetch_assoc($execute)) {
$_SESSION['uploadcoverimg'] = $row['uploadcoverimg'];
$_SESSION['bookname'] =$row['bookname'];
$_SESSION['uname'] =$row['uname'];
$_SESSION['summary'] =$row['summary'];
$_SESSION['thoughts'] =$row['thoughts'];
$_SESSION['pdf'] = $row['pdf'];
$_SESSION['date'] = $row['date'];
echo "<div class='container' align='center'>
<a href='readbook.php'>
<div class='box'>
<div class='imgbox'>
<img src='upload/".$row['uploadcoverimg']."'>
</div>
<div class='content'>
<h3>".$row['bookname']." <i class='fas fa-chevron-circle-right'></i>".$row['uname']."</h3>
<p>".$row['summary']."</p>
</div>
</div>
</a>
<div class='outcome'>
<div class='heart'>
<i class='fas fa-heart'></i>
</div>
<div class='eye'>
<i class='fas fa-eye'></i>
</div>
<div class='ratings'>
<i class='fas fa-star-half-alt'></i>
</div>
</div>
<div class='scrollmenu1'>
<a href='#home' style='border-radius: 10px;margin-top: 10px; background-color: black;color: white; width: 65px;height: 30px;box-sizing: border-box;'>Horror</a>
<a href='#news' style='border-radius: 10px;margin-top: 10px; width: 65px;height: 30px;box-sizing: border-box; background-color: #0a3da3;color: white;'>Sci-Fi</a>
<a href='#contact' style='border-radius: 10px;margin-top: 10px; background-color: #ff69b4;color: white; width: 65px;height: 30px;box-sizing: border-box;'>Love</a>
</div>
<div class='content1'>
<h2>Time</h2>
<p><br>
Writers Thoughts about this book:
".$row['thoughts']."
</p>
</div>
</div>";
}
?>在我的sql代码中,我使用了id、uname、书名、摘要、思考、上传、pdf、日期。
readbook.php
<img class='bookcover' src='Desert.jpg'>
<div class='heading'>
<h3><?php echo $_SESSION['bookname']; ?> <i class='fas fa-chevron-circle-right'></i><?php echo $_SESSION['uname'];?></h3>
</div>
<div class='container'>
<div class="half_star">
<i id='half_star' class='fas fa-star-half-alt'></i>
</div>
<div class="comment">
<i id='comment' class='fas fa-comments'></i>
</div>
<div class="like">
<i id='like' class='fas fa-thumbs-up'></i><br>
</div>
<div class="date">
<i id='date' class='fas fa-calendar-alt'></i><br>
<?php echo $_SESSION['date'];?>
</div>
<div class="share">
<i id='share' class='fas fa-share'></i>
</div>
<div class='scrollmenu1'>
<a class='horror' href='#home' color='white'>Horror</a>
<a class='sci-fi' href='#news'>Sci-Fi</a>
<a class='love' href='#contact'>Love</a>
</div>
</div>
<div class='summary'>
<h1>Summary of the Book</h1>
<p><?php echo $_SESSION['summary'];?></p>
</div>
<div class="thoughts2">
<h2 class="quotes_head">Thoughts of the Writer</h2>
<p><?php echo $_SESSION['thoughts'];?></p>
</div>
<div class="storyhead">
<h1>Let's start the story:</h1>
</div>
<div class="taskbar">
<button class="bookmark"><i id="bookmark" class="fas fa-bookmark"></i>Bookmark</button>
<button class="unlock"><i id="unlock" class="fas fa-unlock"></i>Unlock</button>
<button class="download">Download</button>
</div>
<div class="pages">
<a href="upload/<?php echo $_SESSION['pdf'];?>">click here!</a>
<iframe src="upload/<?php echo $_SESSION['pdf'];?>" width="1000px" height="500px"></iframe>
</div>如果有人能帮助我的话,那我很感谢你,因为这与我的职业规划有关。谢谢
发布于 2020-02-25 17:06:09
使用此功能:
https://www.php.net/manual/en/function.http-build-query.php
而不是这样:
$_SESSION['uploadcoverimg'] = $row['uploadcoverimg'];
$_SESSION['bookname'] =$row['bookname'];
$_SESSION['uname'] =$row['uname'];
$_SESSION['summary'] =$row['summary'];
$_SESSION['thoughts'] =$row['thoughts'];
$_SESSION['pdf'] = $row['pdf'];
$_SESSION['date'] = $row['date'];用这个:
$query_string = http_build_query($row);更改href url,以便将'?$query_string‘添加到URL中。
<a href='readbook.php?<?php echo $query_string?>'>在您的readbook.php中使用$_GET[]而不是$_SESSION[];
查询字符串的长度有一些限制,但在您的情况下,我认为您有足够小的数据集可以传递。
正确的解决方案是在MySQL中使用readbook.php连接,同时只从上一页传递一个图书id,这样您就可以使用where子句(即从book_id =x的图书中选择*)从数据库中选择确切图书的信息。
https://stackoverflow.com/questions/60398570
复制相似问题