Php 在多个foreach循环表中添加if-else语句
我有一个表,它使用Php 在多个foreach循环表中添加if-else语句,php,mysql,laravel,Php,Mysql,Laravel,我有一个表,它使用FOREACH LOOP从数据库循环其值。当我将IF-ELSE语句插入到另一个FOREACH循环的第一个循环中时,第一个循环似乎没有问题,td开始不再对齐。这意味着,如果该值为空,它将隐藏单元格,并且第一个循环中的其他值将被向前推 请注意,我正在使用不同的服务器数据库,它们是SQL和MYSQL。SQL是我的主要数据库,mysql用于插入、更新和删除表中名为“NOTES”的文本区域 这是来自我的控制器的查询 $getNote1 = DB::connection('mysql')
FOREACH LOOP
从数据库循环其值。当我将IF-ELSE语句
插入到另一个FOREACH循环
的第一个循环中时,第一个循环似乎没有问题,td
开始不再对齐。这意味着,如果该值为空,它将隐藏单元格,并且第一个循环中的其他值将被向前推
请注意,我正在使用不同的服务器数据库,它们是SQL
和MYSQL
。SQL是我的主要数据库,mysql用于插入、更新和删除表中名为“NOTES”的文本区域
这是来自我的控制器的查询
$getNote1 = DB::connection('mysql')->table('note1')->select('stockcode', 'note')->orderBy('stockcode', 'ASC')->get();
$getNote2 = DB::connection('mysql')->table('note2')->select('stockcode', 'note')->orderBy('stockcode', 'ASC')->get();
$getNote3 = DB::connection('mysql')->table('note3')->select('stockcode', 'note')->orderBy('stockcode', 'ASC')->get();
$getNote4 = DB::connection('mysql')->table('note4')->select('stockcode', 'note')->orderBy('stockcode', 'ASC')->get();
return view('posts.index')->with('title', $title)->with('query', $query)->with('getNote1', $getNote1)->with('getNote2', $getNote2)->with('getNote3', $getNote3)->with('getNote4', $getNote4);
这是我的表格代码
<table id="table1" class="table table-bordered">
<thead>
<tr>
<th style="display:none;">Stock Code</th>
<th>Stock Name</th>
<th>Note 1</th>
<th>Note 2</th>
<th>Note 3</th>
<th>Note 4</th>
<th>Order Level</th>
<th>Qty Level</th>
<th>Balance</th>
<th>Purchase Price</th>
<th>UOM</th>
@for ($i=0; $i<=12; $i++)
<th><?php echo date('Y/m', strtotime('-'.$i.' month', strtotime($getDate)));?></th>
@endfor
</tr>
</thead>
<tbody>
<!-- Foreach loop from db -->
@foreach ($query as $val)
<?php
$stockcode = $val->StockCode;
$stockname = $val->StockName;
$currentbalance = $val->CurrentBalance;
$purchaseprice = $val->PurchasePrice;
$baseuom = $val->BaseUOM;
?>
<tr>
<td style="display:none;">{{ $val->StockCode }}</td>
<td class="text-nowrap align-middle">{{ $val->StockName }}</td>
@foreach($getNote1 as $note1)
@if($note1->stockcode == $stockcode)
<td><textarea rows="2" cols="10" name="note1" class="note1 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}">{{ $note1->note }}</textarea></td>
@else
<td><textarea rows="2" cols="10" name="note1" class="note1 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}"></textarea><td>
@endif
@endforeach
<td><textarea rows="2" cols="10" name="note2" class="note2 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}"></textarea></td>
<td><textarea rows="2" cols="10" name="note3" class="note3 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}"></textarea></td>
<td><textarea rows="2" cols="10" name="note4" class="note4 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}"></textarea></td>
<td><input type="text" id="orderlevel" class="text-right"></td>
<td><input type="text" id="qtylevel" class="text-right"></td>
<td class="text-right align-middle">{{ number_format($currentbalance, 2) }}</td>
<td class="text-right align-middle">{{ number_format($purchaseprice, 2) }}</td>
<td class="text-center align-middle">{{ $baseuom }}</td>
@for ($i=1; $i<=13; $i++)
<?php
//looping variables
$Qty = 'Qty'.$i;
$Date = 'Date'.$i;
?>
<td class="text-right align-middle">
@if($val->$Qty > 0)
<a id="viewdetails" data-toggle="modal"
data-productid="{{$val->Id}}"
data-productname="{{$val->StockName}}"
data-getdate="{{date('Y-m', strtotime($val->$Date))}}"
href="#" data-target="#dataModal">{{ number_format($val->$Qty, 2) }}</a>
@endif
</td>
@endfor
</tr>
@endforeach
<!-- End Foreach loop -->
</tbody>
</table>
股票代码
股票名称
附注1
附注2
附注3
附注4
订单级别
数量级
平衡
购买价格
计量单位
@对于($i=0;$i)
{{$val->StockCode}
{{$val->StockName}
@foreach($getNote1作为$note1)
@如果($note1->stockcode==$stockcode)
{{$note1->note}
@否则
@恩迪夫
@endforeach
{{number_格式($currentbalance,2)}
{{number_格式($purchaseprice,2)}
{{$baseuom}
@对于($i=1;$i不要隐藏单元格,而是在其中放入一个空值
<td><textarea rows="2" cols="10" name="note1" class="note1 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}">
@foreach($getNote1 as $note1)
@if($note1->stockcode == $stockcode)
{{ $note1->note }}
@endif
@endforeach
</textarea></td>
@foreach($getNote1作为$note1)
@如果($note1->stockcode==$stockcode)
{{$note1->note}
@恩迪夫
@endforeach
然后它会很好地对齐不要隐藏单元格,而是在其中放入一个空值
<td><textarea rows="2" cols="10" name="note1" class="note1 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}">
@foreach($getNote1 as $note1)
@if($note1->stockcode == $stockcode)
{{ $note1->note }}
@endif
@endforeach
</textarea></td>
@foreach($getNote1作为$note1)
@如果($note1->stockcode==$stockcode)
{{$note1->note}
@恩迪夫
@endforeach
然后它会很好地对齐很乐意提供帮助。如果它起作用,请接受它作为答案。谢谢:)很乐意提供帮助。如果它起作用,请接受它作为答案。谢谢:)请不要编辑问题的标题以包括“已解决”或类似内容。搜索结果中该问题答案数量的绿色背景表示该问题有一个可接受的答案。@Hoppeduppeanut OK。注意:请不要编辑问题的标题以包含“已解决”或类似内容。搜索结果中该问题答案数量的绿色背景表示该问题有一个可接受的答案。@Hoppeduppeanut OK。注意