【发布时间】:2017-03-04 05:05:48
【问题描述】:
我在数据库中有这样的值:
Row 1 : ["2","3"]
Row 2 : ["1","3"]
Row 3 : ["2","3","4"]
在前端我选择了所有行,现在我想显示相似值的计数。 例如:上述代码中所需的 o/p:计数为 1 = 1 、 2 = 2 、 3 = 3 、 4 = 1
当我 json_decode 上面的值并使用 print_r 时,我得到了这样的结果:
Array ( [0] => 2 [1] => 3 )
Array ( [0] => 1 [1] => 3 )
Array ( [0] => 2 [1] => 3 [2] => 4 )
注意:行的列表可以增加,我怎样才能找到相似的值。
我尝试了 array_intersect 如图所示 here ,但没有奏效。
例如:图片在这里 Please Note Data in image, is different from above data
获取上述数据的代码:
$conn = new mysqli("localhost", "root", "", "ams");
$query="SELECT * FROM attendance WHERE subject = '$subj'";
$result = $conn->query($query);
<table class="table table-responsive">
<tr>
<th>Sr. No</th>
<th>Col 1 </th>
<th>Col 2</th>
</tr>
<form method="post">
<?php
$i=1;
if (mysqli_num_rows($result) > 0) {
while ($row=mysqli_fetch_assoc($result)) {
$data = $row['att'];
$data = json_decode($data);
echo "<tr>";
echo "<td>" . $i . "</td>";
echo "<td>" . $row['date1'] . "</td>";
echo "<td>" . print_r($data) . "</td>";
echo "</tr>";
$i++;
}
}
?>
</form>
</table>
【问题讨论】:
-
我很困惑。你用的是什么数据库?
-
我正在使用 MYSQL 数据库
-
您不应该将其作为回应。你用什么驱动来连接Mysql?你能在这个问题中显示一些代码吗?很模糊。
-
我可以在 PDO 中给你答案吗?我不确定如何利用
mysqli_? -
@McStuffins:是的没问题