Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 显示带有某些条件的数据库字段_Php_Html_Forms_Mysqli - Fatal编程技术网

Php 显示带有某些条件的数据库字段

Php 显示带有某些条件的数据库字段,php,html,forms,mysqli,Php,Html,Forms,Mysqli,我想在管理员单击每个客户的查看账单按钮时显示该客户的发票账单。另外,当客户名称相同时,我想在一张发票中显示所有报纸的详细信息。我已经包括了相关代码和数据库快照 c_details.php <?php session_start(); include_once("connect.php"); $query="SELECT * FROM sub_details"; $result=mysqli_query($conn,$query); ?> <table align="ce

我想在管理员单击每个客户的查看账单按钮时显示该客户的发票账单。另外,当客户名称相同时,我想在一张发票中显示所有报纸的详细信息。我已经包括了相关代码和数据库快照

c_details.php

<?php
session_start();
include_once("connect.php");
$query="SELECT * FROM  sub_details";
$result=mysqli_query($conn,$query);
?>



<table align="center">     
    <h3 style="color: black; font-weight: bold; text-align: center;"> 
    Subscription details</h3><br>
    <tr>            
      <th style="text-align: center;">Id</th>
      <th style="text-align: center;">Name</th>
      <th style="text-align: center; width: 900px">Newspaper</th>
      <th style="text-align: center;">Duration</th>
      <th style="text-align: center;">Price</th>
      <th style="text-align: center; width: 800px">Subscription date</th>
      <th style="text-align: center;">Remaining Days</th>
      <th style="text-align: center;">Bill</th>
    </tr>
    <?php while($rows=mysqli_fetch_assoc($result)) {
      ?>


      <tr>
        <td><?php echo $rows['id']; ?></td>
        <td><?php echo $rows['name']; ?></td>
        <td><?php echo $rows['newspaper']; ?></td>
        <td><?php echo $rows['duration']; ?></td>
        <td><?php echo $rows['price']; ?></td>
        <td><?php echo $rows['sdate']; ?></td>
        <?php  echo var_dump($result->fetch_all(MYSQLI_ASSOC));
        $date1=date_create();
        $date2=date_create($rows['edate']);
        $interval=date_diff($date2,$date1)->format("%a days");
         ?>
         <td><?php echo $interval; ?></td>
         <td>
     <form action="invoice.php" method="GET">   
     <?php $invoiceId = $rows['name']; ?>  
   <button type="submit" onclick= "window.open('invoice.php?name= '<?php echo  
   $rows['name']; ?>)" class="btn btn-primary btn-lg" value="submit" >
   View bill</button></td>
      </form>                                                               
      </tr>
      <?php } ?>
   </table>

订阅详细信息
身份证件 名称 报纸 期间 价格 认购日期 剩余天数 比尔
首先,您应该在
c_details.php
中传递每条记录的发票ID,以便以后识别它们:

<button type="submit" onclick= "window.open('invoice.php?id='<?php echo $rows['id']; ?>)" class="btn btn-primary btn-lg" value="submit" >View bill</button>
如果您使用的是PHP 7.0或更高版本,则可以使用以下命令简化代码:


我强烈建议您了解。

首先,您应该在
c_details.php
中传递每条记录的发票ID,以便以后识别:

<button type="submit" onclick= "window.open('invoice.php?id='<?php echo $rows['id']; ?>)" class="btn btn-primary btn-lg" value="submit" >View bill</button>
如果您使用的是PHP 7.0或更高版本,则可以使用以下命令简化代码:


强烈建议您了解。

请提供您想要做的更多详细信息。还请注意,PHP是一种后端语言,您需要在前端进行交互才能实现这一点。请提供您想要做的更多详细信息。还要注意,PHP是一种后端语言,您需要在前端进行交互才能实现这一点。@dharman您完全正确。我刚刚更新了我的答案很好,但OP似乎在使用mysqli,而不是PDO。PHP中还有
??
运算符,因此不必使用长三元数。您只需执行
$invoiceId=$\u GET['id']??null
@dharman null合并是PHP7+的一个特性,我不知道他/她正在使用哪个版本。但我会用免责声明更新它。@CaduDeCastroAlves我尝试了你的方法链接工作正常,但我没有得到输出。我收到了这些错误注意:未定义变量:第52行的C:\xampp\htdocs\NEWSCART\invoice.php中的结果警告:mysqli\u fetch\u assoc()期望参数1为mysqli\u result,C:\xampp\htdocs\NEWSCART\invoice.php中的第行中给出了null52@mahesh您需要启用错误报告@达曼,你完全正确。我刚刚更新了我的答案很好,但OP似乎在使用mysqli,而不是PDO。PHP中还有
??
运算符,因此不必使用长三元数。您只需执行
$invoiceId=$\u GET['id']??null
@dharman null合并是PHP7+的一个特性,我不知道他/她正在使用哪个版本。但我会用免责声明更新它。@CaduDeCastroAlves我尝试了你的方法链接工作正常,但我没有得到输出。我收到了这些错误注意:未定义变量:第52行的C:\xampp\htdocs\NEWSCART\invoice.php中的结果警告:mysqli\u fetch\u assoc()期望参数1为mysqli\u result,C:\xampp\htdocs\NEWSCART\invoice.php中的第行中给出了null52@mahesh您需要启用错误报告。
$invoiceId = isset($_GET['id']) ? $_GET['id'] : null;
if($invoiceId) {
    $query = $conn->prepare("SELECT * FROM sub_details, signup_c WHERE id = ? limit 1";
    $query->bind_param('s', $invoiceId);
    $query->execute();
    $result = $query->get_result();
}
$invoiceId = $_GET['id'] ?? null;