gpt4 book ai didi

php - 如何使用php打印存储在mysql数据库中的特定数据

转载 作者:太空宇宙 更新时间:2023-11-04 00:54:52 24 4
gpt4 key购买 nike

您好,我在我的网站上添加了一个功能,用户可以使用以下代码取消预订的机票:cancel.php

<?php
session_start();
include('config.php');
mysqli_query($con,"delete from tbl_bookings where book_id='".$_GET['id']."'");
$_SESSION['success']="Booking Cancelled Successfully";
header('location:profile.php');
?>

我尝试在同一张票上添加一个功能,用户可以取消打印票,这样用户就可以打印这张票了,我使用的代码是:print.php

<?php
session_start();
include('config.php');
window.print(mysqli_query($con,"select from tbl_bookings where book_id='".$_GET['id']."'"));
header('location:profile.php');
?>

在一个名为 profile.php 的类中指向这两个类的链接,这一点位于它表示的行中:

                            <a href="cancel.php?id=<?php echo $bkg['book_id'];?>">Cancel </a>/<a href="print.php?id=<?php echo $bkg['book_id'];?>">Print Ticket</a>

如果你能告诉我如何打印这些数据我会很高兴..谢谢

$bkg的使用

$bk=mysqli_query($con,"select * from tbl_bookings where user_id='".$_SESSION['user']."'");
if(mysqli_num_rows($bk))
{
?>
<table class="table table-bordered">
<thead>
<th>Booking Id</th>
<th>Movie</th>
<th>Theatre</th>
<th>Screen</th>
<th>Show</th>
<th>Seats</th>
<th>Price</th>
<th></th>
</thead>
<tbody>
<?php
while($bkg=mysqli_fetch_array($bk))
{
$m=mysqli_query($con,"select * from tbl_movie where movie_id=(select movie_id from tbl_shows where s_id='".$bkg['show_id']."')");
$mov=mysqli_fetch_array($m);
$s=mysqli_query($con,"select * from tbl_screens where screen_id='".$bkg['screen_id']."'");
$srn=mysqli_fetch_array($s);
$tt=mysqli_query($con,"select * from tbl_theatre where id='".$bkg['t_id']."'");
$thr=mysqli_fetch_array($tt);
$st=mysqli_query($con,"select * from tbl_show_time where st_id=(select st_id from tbl_shows where s_id='".$bkg['show_id']."')");
$stm=mysqli_fetch_array($st);
?>
<tr>
<td>
<?php echo $bkg['ticket_id'];?>
</td>
<td>
<?php echo $mov['movie_name'];?>
</td>
<td>
<?php echo $thr['name'];?>
</td>
<td>
<?php echo $srn['screen_name'];?>
</td>
<td>
<?php echo $stm['start_time'];?>
<?php echo $stm['name'];?>
</td>
<td>
<?php echo $bkg['no_seats'];?>
</td>
<td>
£ <?php echo $bkg['amount'];?>
</td>
<td>
<?php if($bkg['ticket_date']<date('Y-m-d'))
{
?>
<i class="glyphicon glyphicon-ok"></i>
<?php
}
else
{?>
<a href="cancel.php?id=<?php echo $bkg['book_id'];?>">Cancel </a>/<a href="print.php?id=<?php echo $bkg['book_id'];?>">Print Ticket</a>
<?php
}
?>
</td>
</tr>
<?php
}
?></tbody>

enter image description here

最佳答案

  1. 您不能在 PHP 代码中调用 window.print(),因为它是一个 javascript 函数

  2. header('location:profile.php'); 将在 javascript 有机会执行代码之前重定向页面。用打印页面后执行的 javascript 代码替换该代码。

你的 print.php:

<?php
session_start();
include('config.php');
$result = mysqli_query($con, "select * from tbl_bookings where book_id='{$_GET['id']}'"); // You should replace this with prepare statement
$row = $result->fetch_array();
// assume that your booking table has columns: id, movie_name, time
echo "<table>
<tr><td>Booking ID</td><td>{$row['id']}</td></tr>
<tr><td>Movie Name</td><td>{$row['movie_name']}</td></tr>
<tr><td>Time</td><td>{$row['time']}</td></tr>
</table>";
?>
<script>
window.print();
window.location.href = "profile.php"
</script>

关于php - 如何使用php打印存储在mysql数据库中的特定数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55013986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com