【发布时间】:2020-03-04 19:28:37
【问题描述】:
我需要计算我被选中的列数。
现在我用 reapeat i++ 来做,但我需要在现场使用选定行的数量,但我不能。
我尝试使用fetchAll,但没有得到肯定的结果
($table_fields = $result->fetchAll(PDO::FETCH_COLUMN); print_r($table_fields);)
有人可以帮帮我吗?
我正在使用 IIS 和 MSSQL 2012...
$query2 = "SELECT
SURNAME_USER,
FIRST_NAME_USER,
CR_FACTORY,
CR_LICENC,
EVENT_NAME,
EVENT_DATE_FROM,
EVENT_DATE_TO
FROM dbo.EVENT_CALENDAR_EVENT
join EVENT_CALENDAR_CAR on OBJECT_CAL_ID = CAL_OBJECT_ID
join AA_USER on ID_USER=EVENT_USER_ID
where (SURNAME_USER+' '+FIRST_NAME_USER) like ? and EVENT_DATE_FROM >= ? and EVENT_DATE_TO <= ? order by EVENT_DATE_FROM desc";
$result = $conn->prepare($query2);
$result->bindValue(1, $user_name, PDO::PARAM_STR);
$result->bindValue(2, $datum_od, PDO::FETCH_NUM);
$result->bindValue(3, $datum_do, PDO::FETCH_NUM);
$result->execute();
$count=1;
?>
<div class="col-md-3 mb-3">
<p>Filtr</p>
<input id="myInput" type="text" class="form-control" placeholder="Hledej...">
<br>
</div>
<div>
<table class="table table-hover">
<t>
<th scope="col">Počet cest</th>
<!--<th scope="col">Jméno</th>
<th scope="col">Přijmení</th>-->
<th scope="col">Udalost</th>
<th scope="col">Automobil</th>
<th scope="col">Datum od</th>
<th scope="col">Datum do</th>
</t><tbody id="myTable">
<?php foreach($result as $rows) {
?>
<tr>
<td scope="row"><?php echo $count;?></td>
<!-- <td><?php echo $rows["FIRST_NAME_USER"];?></td>
<td><?php echo $rows["SURNAME_USER"];?></td> -->
<td><?php echo $rows["EVENT_NAME"];?></td>
<td><?php echo $rows["CR_FACTORY"]." ".$rows["CR_LICENC_PLATE"];?></td>
<td><?php echo date('d-m-Y', strtotime($rows["EVENT_DATE_FROM"]));?></td>
<td><?php echo date('d-m-Y', strtotime($rows["EVENT_DATE_TO"]));?></td>
</tr>
<?php
$count++;
}?></tbody></table>
```
【问题讨论】:
-
您在查询中指定的列,那么为什么需要计算它们?
-
我需要在表格右上角显示结果行数。当我使用 i++ 时,我会在生成表格后获取结果,我可以向下使用它,但不能在顶部使用。所以不知道怎么显示。
-
您好。我们在这里不使用
[Solved]标题黑客。请接受下面的答案(通过打勾)或写一个自我答案并接受/打勾。谢谢!
标签: php sql-server pdo