如何从ID表获取名称

时间:2019-11-28 00:25:14

标签: html laravel

我有一个问题,如果我的表PO中的status(String)为1,我需要显示我的数据

这是我的PO表

id | book_name            | stock |status
1  | lala land            | 10    | 0
2  | beauty and the beast | 25    | 1
3  | wawasan              | 15    | 1

我尝试过的

..prev code
@if($po->status == '1')
@foreach($po as $p)
  <tr>
     <td> {{$p->book_name) </td>
     <td> {{$p->stok}} </td>
  </tr>
@endforeach
@endif    




4 个答案:

答案 0 :(得分:4)

@if应该在@foreach

@foreach($po as $p)
  @if($p->status == '1')
    <tr>
       <td> {{$p->book_name}} </td>
       <td> {{$p->stok}} </td>
    </tr>
  @endif
@endforeach

或者,您可以遍历过滤后的集合。

@foreach($po->where('status', 1) as $p)
  <tr>
     <td> {{$p->book_name}} </td>
     <td> {{$p->stok}} </td>
  </tr>
@endforeach

答案 1 :(得分:2)

我认为如果进展顺利

@foreach($po as $p)
  @if($p->status == '1')
    <tr>
       <td>{{ $p->book_name }}</td>
       <td>{{ $p->stok }}</td>
    </tr>
  @endif    
@endforeach

答案 2 :(得分:1)

例如,您的型号名称是PO,

通过控制器功能传递      使用App \ PO;

libname lib "/dir";
run;

proc sql;
CONNECT TO TeraData (Server = 'edw' User =&tduser pass=&tdpass Database = UDW Mode = TeraData);
execute(    create multiset volatile table datanew as

    (select a.name,b.age from table1 a left join table2 b on a.pkey=b.pkey)
        with data primary index (name) on commit preserve rows
    )
BY TeraData;

CREATE TABLE lib.datanew AS (SELECT * FROM CONNECTION TO TeraData (SELECT * FROM datanew));
disconnect from teradata;
quit;

,然后在刀片文件中

 $data= PO::where('status',1)->get();
 return view('bladefilename',compact('data');

答案 3 :(得分:0)

或者也许知道状态是正确的,以避免刀片中有逻辑。

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<html lang="en">

<body>
  <table class="mt-table-edit" border="1">
    <tr>
      <td>first col</td>
      <td><input type="text" name="order"></td>
    </tr>
  </table>


</body>

</html>