Sql query from database

I need help on how I can execute a soft query from sql. I have a php script with an html page that displays the result of a request.

I have this query:

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

From HTML, I have this:

<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>

The query does everything I want, but I need the result to be on the list. Like a counter 1,2,3,4,5 etc.

Is it possible?

+4
source share
3 answers

includes

select count * from ordertable

Then paste this result into the first

0
source
SELECT COUNT(orderid) AS Order_Count
FROM ordertable
WHERE orderid IS NOT NULL
0
source

using foreach loop

<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>

0
source

All Articles