从数据库查询生成的表中缺少值

时间:2014-10-14 13:05:56

标签: php

我在MySQL中创建了一个表,其中包含一个项目,在我的网站上复制了另一个已经从数据库中提取的php页面并试图将其修改为从我的“gigs”中删除。表。它不起作用,我接近疯了:)

这是我的PHP:

<div class="span12">
<h3>View & Manage Your Gigs</h3>
 <table class="table table-striped">
<tr>
<th>Gig ID</th>
<th>Gig Name</th>
<th>Customer</th>
<th>Date</th>
<th>Fee</th>    
<th>Status</th>
<th>Manage</th>
</tr>
<?php
$cnt = ORM::for_table('gigs')->where('gid', $cid)->count();
if ($cnt>0){
    $items = ORM::for_table('gigs')->raw_query($query)->find_many();
    $i='0';
    foreach ($items as $item) {
        $i++;
        $gigid = $item['gigid'];
        $gig_name = $item['gig_name'];
        $gig_customer = $item['gig_customer'];
        $gig_date = $item['gig_date'];
        $gig_fee = $item['gig_fee'];
        $status = $item['gig_status'];

        if ($status=='Booked'){
            $st="<a class=\"btn btn-danger btn-small\" href=\"invoice$ext?_cmd=$gigid\">".$_L['pay_now']."</a>";
        } else {
            $st="<a class=\"btn btn-primary btn-small\" href=\"invoice$ext?_cmd=$gigid\">".$_L['view']."</a>";
        }

        $ext = EXT;
        echo "<tr>
<td>$gigid</td>
<td>$gig_name</td>
<td>$gig_customer</td>
<td>$gig_date</td>
<td>$gig_fee</td>   
 <td>$status</td>
  <td>$st</td>
</tr>";
    }

}

?>
</table>
<?php  echo  $paginate['contents']; ?> 
</div>

当我在我的页面上查看来源时,它正在创建表格标题,但是td没有创建,当然也没有数据显示 - 只是标题..

有什么想法吗?

错误报告给了我:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'gid' in 'where clause'' in /home/content/s/t/o/stolzillusions/html/gigs/lib/d.f.php:387
Stack trace:
#0 /home/content/s/t/o/stolzillusions/html/gigs/lib/d.f.php(387): PDOStatement->execute(Array)
#1 /home/content/s/t/o/stolzillusions/html/gigs/lib/d.f.php(1539): ORM::_execute('SELECT COUNT(*)...', Array, 'default')
#2 /home/content/s/t/o/stolzillusions/html/gigs/lib/d.f.php(549): ORM->_run()
#3 /home/content/s/t/o/stolzillusions/html/gigs/lib/d.f.php(658): ORM->find_one()
#4 /home/content/s/t/o/stolzillusions/html/gigs/lib/d.f.php(610): ORM->_call_aggregate_db_function('count', '*')
#5 /home/content/s/t/o/stolzillusions/html/gigs/cp/views/bmsapp/gig-list.tpl.php(19): ORM->count()
#6 /home/content/s/t/o/stolzillusions/html/gigs/cp/gig-list.php(4): require('/home/content/s...')
#7 {main} thrown in /home/content/s/t/o/stolzillusions/html/gigs/lib/d.f.php on line 387`

4 个答案:

答案 0 :(得分:1)

您还没有为$ query变量设置值,或者我遗漏了什么?

答案 1 :(得分:0)

foreach 循环之前

var_dump print_r($items)。无论您是否正在获取数据,您都会知道。

如果有其他问题,请告诉我。

答案 2 :(得分:0)

而不是

$cnt = ORM::for_table('gigs')->where('gid', $cid)->count();

$cnt = ORM::for_table('gigs')->where('gigid', $cid)->count();

编辑:根据您的评论实际上是这样的:

$cnt = ORM::for_table('gigs')->where('gig_customer', $cid)->count();

答案 3 :(得分:0)

我明白了!这确实是$ Query。

当我改变了这个

$items = ORM::for_table('gigs')->raw_query($query)->find_many();

对此:

$items = ORM::for_table('gigs')->find_many();