[英]Get records from database and insert in specific row
我有一個選擇查詢,該查詢使用INNER JOIN
從2個表中檢索所有數據。 其中一個表稱為Rack_Monitor
,另一個表稱為Rack_Content
。 Rack_Monitor有一個名為TotalUnits
的列(例如48)。 Rack_Content有一個名為Units
的列(例如3或3; 4,如果分隔符包含多個單位,則定界符為;)。
題:
現在,我需要在Twig中構建一個表,該表循環48次(TotalUnits),並檢查是否有任何要填充的內容。 如果不是,則該行必須為空。 該數組將從0開始,並且該數組的內容的單位為3; 4,因此必須將其放在表的第三行和第四行。
代碼循環48次:
<table class="table" id="diagnosis_list">
<thead>
<tr>
<th>Unit</th>
</tr>
</thead>
<tbody>
{% set TotalUnits = RackContent[0].TotalUnits %}
{% for i in 1.. TotalUnits %}
<tr>
<td class="priority" style="">{{ i }}</th>
</tr>
{% endfor %}
</tbody>
</table>
此代碼顯示該表的48行數字。
我陷入下一個代碼。 這就是到目前為止。 我在正確的軌道上嗎?:
<div class="col-xs-5 col-md-7 col-lg-7">
<table class="table" id="diagnosis_list">
<thead>
<tr>
<th>Name</th>
<th>Intern IP</th>
<th>Extern IP</th>
<th>Backup</th>
<th> </th>
</tr>
</thead>
<tbody>
{% for i in 0..TotalUnits %}
{% if RackContent[i] is defined %}
{% set UnitSplit = RackContent[i].Units|split(';') %}
<tr>
<td><h5>HostName</h5><small>Webserver</small></td>
<td><h5>InternIP</h5><small>WebserverInternIP</small></td>
<td><h5>IPMI IP</h5><small>WebserverIP</small></td>
<td><h5>BackupserverIP</h5></td>
<td><a class='btn btn-warning'>
<i class="fa fa-edit text-white"></i>
</a>
<a class='btn btn-danger'>
<i class="fa fa-trash-o text-white" onclick="Delete(2)"></i>
</a>
</td>
</tr>
{% else %}
<tr>
<td><h5>Empty</h5><small>Empty</small></td>
<td><h5>Empty</h5><small>Empty</small></td>
<td><h5>Empty</h5><small>Empty</small></td>
<td><h5>Empty</h5></td>
<td><a class='btn btn-warning'>
<i class="fa fa-edit text-white"></i>
</a>
<a class='btn btn-danger'>
<i class="fa fa-trash-o text-white" onclick="Delete(2)"></i>
</a>
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
為什么要設置2個表是因為它是可拖動的表。 因此數字是靜態的,將無法移動。 帶有內容的另一個表可以上下移動。
代碼尚未完成,但是我只想知道你們是否將以相同的方式對其進行編程,或者是否有更有效的方法來進行編程?
這就是我做到的。 現在工作正常。
<table class="table table-condensed">
<thead>
<tr>
<th>ID</th>
<th>Hardware</th>
<th>Name</th>
<th>Intern IP</th>
<th>Extern IP</th>
<th>Backup</th>
<th>Options</th>
</tr>
</thead>
<tbody>
{% for i in 1..(TotalUnits) %}
{% set ID = i %}
{% set FoundIt = 0 %}
{% for R in RackContent %}
{% for U in R.Units %}
{% if loop.length == 2 %}
{% if U == i and loop.index == 1 %}
<tr class="success">
<td>{{ ID }}</td>
<td rowspan="2"><h5>{{ R.Name }}</h5></td>
<td rowspan="2"><h5>{{ R.HostName }}</h5><small>{{ R.WebServer }}</small></td>
<td rowspan="2"><h5>{{ R.InternIP }}</h5><small>{{ R.WebServerInternIP }}</small></td>
<td rowspan="2"><h5>{{ R.IPMIIP }}</h5><small>{{ R.WebServerIP }}</small></td>
<td rowspan="2"><h5>{{ R.BackupServer }}</h5></td>
<td rowspan="2"><div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Options
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#" data-toggle="modal" data-target="#myModal"><i class="fa fa-eye text-blue"></i>Open</a></li>
<li><a href="#" data-toggle="modal" data-target="#myModal"><i class="fa fa-edit text-orange"></i>Edit</a></li>
<li><a href="#" data-toggle="modal" data-target="#myModal"><i class="fa fa-trash-o text-red"></i>Delete</a></li>
</ul>
</div></td>
</tr>
{% set FoundIt = 1 %}
{% elseif U == i and loop.index == 2%}
<tr class="success">
<td>{{ ID }}</td>
</tr>
{% set FoundIt = 1 %}
{% endif %}
{% elseif loop.length == 1 %}
{% if U == i and loop.index == 1 %}
<tr class="success">
<td>{{ ID }}</td>
<td><h5>{{ R.Name }}</h5></td>
<td><h5>{{ R.HostName }}</h5><small>{{ R.WebServer }}</small></td>
<td><h5>{{ R.InternIP }}</h5><small>{{ R.WebServerInternIP }}</small></td>
<td><h5>{{ R.IPMIIP }}</h5><small>{{ R.WebServerIP }}</small></td>
<td><h5>{{ R.BackupServer }}</h5></td>
<td><div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Options
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#" data-toggle="modal" data-target="#myModal"><i class="fa fa-eye text-blue"></i>Open</a></li>
<li><a href="#" data-toggle="modal" data-target="#myModal"><i class="fa fa-edit text-orange"></i>Edit</a></li>
<li><a href="#" data-toggle="modal" data-target="#myModal"><i class="fa fa-trash-o text-red"></i>Delete</a></li>
</ul>
</div></td>
</tr>
{% set FoundIt = 1 %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% if FoundIt == 0 %}
<tr class="active">
<td>{{ ID }}</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.