【问题标题】:Issue with using php and sql to add data to datables使用 php 和 sql 将数据添加到数据表的问题
【发布时间】:2017-07-10 01:25:41
【问题描述】:

所以我正在尝试使用 php 和 mysql 将数据放入我网站上的数据表中。我在文件顶部写了一些代码来确认我正在正确访问我的数据库。当我手动输入一些数据时,表格显示正确,但使用我的 php 代码,表格显示“表格中没有可用数据”。对我的 php 有什么问题有任何想法吗?

    $q = "SELECT tickets.ticket_id, tickets.section, tickets.row, tickets.price, users.first_name as first_name, users.last_name as last_name 
          FROM tickets 
          LEFT JOIN users 
          ON tickets.seller_id = users.umid
          Where(tickets.game_id = '$g')";

    $r = @mysqli_query ($dbc, $q);



     <table id="example" class="display" cellspacing="0" width="100%">
     <thead>
        <tr>
           <th>Section</th>
           <th>Row</th>
           <th>Price</th>
           <th>Seller</th>
        </tr>
     </thead>
     <tbody>

        <?php
           while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

           echo '
              <tr>
                 <td>'.$row["section"].'</td>
                 <td>'.$row["row"].'</td>
                 <td>'.$row["price"].'</td>
                 <td>'.$row["first_name"]. " ". $row["last_name"]. '</td>
              </tr>
              ';
           }
        ?>

     </tbody>
  </table>

This is what the table looks like

Link to the webpage

【问题讨论】:

  • 您在运行时会遇到任何错误吗..?
  • No data available in table 的条件在哪里?
  • 显示$r的内容
  • 不要使用@,这只会对你隐藏有用的错误。
  • 我在帖子中更新了我的代码

标签: php mysql twitter-bootstrap datatables


【解决方案1】:

找出问题所在。我在代码的前面循环了我的行,所以当我想将信息放入表中时,它位于数组的末尾。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-25
    • 1970-01-01
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    相关资源
    最近更新 更多