Javascript 如何再次检查数组结果,以便在PHP中将结果(通过其中一个字段)排列到表中
我必须按地点、供应商或资产描述进行“详细报告” 问题是,虽然我得到了正确的结果,但我希望显示如下结果 地点1: 此表包含位于该位置的资产 地点2: 资产位于此位置的表 与提供者和描述相同 我的PHP和其他语言知识有限。所以,我想做一些像 获取数组(完整的数组而不仅仅是一行),然后检查Javascript 如何再次检查数组结果,以便在PHP中将结果(通过其中一个字段)排列到表中,javascript,php,jquery,html-table,resultset,Javascript,Php,Jquery,Html Table,Resultset,我必须按地点、供应商或资产描述进行“详细报告” 问题是,虽然我得到了正确的结果,但我希望显示如下结果 地点1: 此表包含位于该位置的资产 地点2: 资产位于此位置的表 与提供者和描述相同 我的PHP和其他语言知识有限。所以,我想做一些像 获取数组(完整的数组而不仅仅是一行),然后检查数组[i]中的位置是否等于数组[i+1],然后打印一个和行数据,否则结束该表,然后创建一个新表 地点: 最后是另一个表,其中的行与该位置匹配 如何在PHP中实现这一点 示例: 我现在拥有的 这就是我想做的 这就是我在
数组[i]
中的位置是否等于数组[i+1]
,然后打印一个
和行数据,否则结束该表,然后创建一个新表
地点:
最后是另一个表,其中的行与该位置匹配
如何在PHP中实现这一点
示例:
我现在拥有的
这就是我想做的
这就是我在PHP中所做的
<?php
echo "<table>
<thead>
<tr>
<th></th>
<th>Ubicación</th>
<th>Código</th>
<th>Descripción</th>
<th>Costo Adquisición</th>
<th>Saldo a Depreciar de Activos</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>";
while($row = odbc_fetch_array($result)){
echo"<td></td>
<td><b>".$row["Ubicacion_actual"]."</b></td>
<td>".$row["Activo"]."</td>
<td>".$row["Descripcion"]."</td>
<td>".number_format($row["Costo_Adquisicion"],4)."</td>
<td>".number_format($row["Saldo_sin_depreciar"],4)."</td>
<td></td>
</tr>";
}
echo "</tbody>
</table>";
odbc_close($dbhandle);
?>
首先,应将所有数据放入本地数组,然后使用本地数组进行处理 所以你可以:
$theArray = array(); //Array to hold data
$headerIds = array(); //Array to hold unique id of the records
while($row = odbc_fetch_array($result)){
array_push($theArray, $row);
if(!in_array($row["Ubicacion_actual"], $headerIds))
{
array_push($headerIds, $row["Ubicacion_actual"]);
}
}
odbc_close($dbhandle);
foreach($headerIds as $id)
{
//Print the header info
//...
//Loop through each item in your data array until its id matches the header id
foreach($theArray as $dataItem)
{
if($dataItem["Ubicacion_actual"] == $id) //This line item has the same id as the header
{
//Display the table row data
}
}
}
嗨,唯一的问题是,这些表没有ID'doesn不是每一行都有一个“Ubicacion\u actual”吗?我以为你是在用这个对结果进行分组。当我有$id时,我使用它作为变量来分组数据。所以任何具有相同“Ubicacion\u actual”的内容都将在同一组中。这样做了,在$theArray和$HeaderID上获取并使用var\u转储。。。我在这里遇到了一个错误:if(!in_数组($row[“Ubicacion\u actual”]),$headerIds),所以我将它改为:if(!in_数组($row[“Ubicacion\u actual”],$headerIds));全部代码都在这里:哦,是的,我打电话给inarray时出错了。那么它现在起作用了吗?是的!我修复了它,我得到它的错误是由于一个错误;如果不是那样的话。。。。非常感谢。