4

我需要一些关于如何从 sql 进行软查询的帮助。我有一个带有显示查询结果的 html 页面的 php 脚本。

我有这个查询:

 $ready_orders = DB::query( 'SELECT * FROM ordertable where orderid is NOT null ORDER by id DESC')->fetchAll( DB::FETCH_ASSOC ); 

从 HTML 我有这个;

<tal:block tal:condition="exists:orders">
  <table>
    <tr>
      <td>amount</td>
      <td> want counter here</td>
      <td>result 1</td>
      <td>result 2</td>
      <td>result 3</td>
      <td>result 4</td>
    </tr>
    <tr tal:repeat="order orders">
      <td tal:content="">
      ....
      </td>

      <td tal:content="order/id">
      ....
      </td>


      <td tal:content="order/orderid">
      ....
      </td>
      <td tal:content="order/productid">
      ....
      </td>
      <td tal:content="order/processed">
      ....
      </td>

      <td>
      </td>
    </tr>
  </table>

该查询正在做我想做的所有事情,但需要将结果放在列表中。像一个计数器 1,2,3,4,5 等

可能吗?

4

3 回答 3

0

包括一个

select count * from ordertable

然后将此结果插入第一个

于 2015-08-26T14:56:03.033 回答
0

使用 foreach 循环

<tal:block tal:condition="exists:orders">
  <table>
   <tr>
      <td>amount</td>
     <?php 
       $i = 1;
       foreach($ready_orders as $result){ ?>
          <td>result <?php echo $i++; ?></td> //your counter
       <?php } ?>
   </tr>

  <tr tal:repeat="order orders">
    <td tal:content="">
        ....
     </td>

  <td tal:content="order/id">
  ....
  </td>


  <td tal:content="order/orderid">
  ....
  </td>
  <td tal:content="order/productid">
  ....
  </td>
  <td tal:content="order/processed">
  ....
  </td>

  <td>
  </td>
</tr>

于 2015-08-26T15:26:53.180 回答
0
SELECT COUNT(orderid) AS Order_Count
FROM ordertable
WHERE orderid IS NOT NULL
于 2015-08-26T15:22:29.730 回答