mysqli_fetch_array()期望参数1为mysqli_result,第297行的C:\ xampp \ htdocs \ wst \ admin1.php中给出布尔值

时间:2017-03-26 08:59:19

标签: php mysql

我想添加2行表中包含数字的表格,我希望表格的新行中有2行的总和

我使用sql查询编写了我的代码..

<?php
    $con =  mysqli_connect("localhost", "root", "", "project");
    if(!$con) {
      die('not connected');
    }
    $con =  mysqli_query($con, "SELECT addplace, stayamount, foodamount, airlinesamount, noofdays, totalamount AS sum(stayamount + foodamount + airlinesamount) choose FROM adddetails");

?>
<div class="container">
  <center><h2>view packages</h2></center>  
  <table class="table table-bordered">
    <th>place</th>
    <th>stay cost</th>
    <th>food cost</th>
    <th>flight cost</th>
    <th>no of days</th>
    <th>total amount</th>
    <th>image</th>

    <?php while($row = mysqli_fetch_array($con, MYSQLI_ASSOC)) { ?>
    <tr>
      <td><?php echo $row['addplace']; ?></td>
      <td><?php echo $row['stayamount']; ?></td>
      <td><?php echo $row['foodamount'] ;?></td>
      <td><?php echo $row['airlinesamount'] ;?></td>
      <td><?php echo $row['noofdays'] ;?></td>
      <td><?php echo $row['totalamount'] ;?></td>
      <td><?php echo $row['choose'] ;?></td>
    </tr>
    <?php } ?>
  </table>
</div>

我收到了错误。

任何人都可以重写我的sql查询或php添加包含数字的2行,我希望新行中的行总和

[phpmyadmin中的数据库图像] [1]

[我的网页(图片)中的表格] [2]

感谢你

图片代码

<input  name="choose"  class="form-control" type="file" >

我希望所选图像在我的网站中显示为完整图像,而不是图像的名称 我该怎么办..

[在选择的行中存储图像] [3]

3 个答案:

答案 0 :(得分:0)

如下所示更改您的onAddSubmit() { const data = { institution: this.institution, degree: this.degree, year: this.year } addData(data) { let headers = new Headers(); headers.append('Content-Type', 'application/json'); return this.http.post('./data.json', data, { headers: headers }).map(res => res.json()); } } 查询并尝试。我正在考虑mysqlpackageid密钥

primary

答案 1 :(得分:-1)

将您的查询更改为:

SELECT addplace, stayamount, foodamount, airlinesamount, noofdays,
       totalamount, sum(stayamount + foodamount + airlinesamount) AS choose
FROM adddetails

然后尝试。

答案 2 :(得分:-1)

虽然它不是问题的根源,但是你用结果覆盖你的$ con变量并不好。而是使用$result来存储mysqli_query()

的结果
<?php
    $con = mysqli_connect("localhost", "root", "", "project");
    if(!$con) {
      die('not connected');
    }

    $result = mysqli_query($con, "SELECT addplace, stayamount, foodamount, airlinesamount, noofdays, totalamount AS sum(stayamount + foodamount + airlinesamount) choose FROM adddetails");
    print_r($result); # make sure u have expected output here, if it works delete this line

?>
<div class="container">
  <center><h2>view packages</h2></center>  
  <table class="table table-bordered">
    <th>place</th>
    <th>stay cost</th>
    <th>food cost</th>
    <th>flight cost</th>
    <th>no of days</th>
    <th>total amount</th>
    <th>image</th>

    <?php while($row = mysqli_fetch_assoc($result)) { ?>
    <tr>
      <td><?php echo $row['addplace']; ?></td>
      <td><?php echo $row['stayamount']; ?></td>
      <td><?php echo $row['foodamount'] ;?></td>
      <td><?php echo $row['airlinesamount'] ;?></td>
      <td><?php echo $row['noofdays'] ;?></td>
      <td><?php echo $row['totalamount'] ;?></td>
      <td><?php echo $row['choose'] ;?></td>
    </tr>
    <?php } ?>
  </table>
</div>