我有一个页面,可以从数据库中获取信息。
日期 - 备注 - account_type
在account_type中,我有3种类型的帐户PS:A - B - C.
$Qdaily_entriesD = mysqli_query($connect, "SELECT * FROM daily_entries ORDER BY account_type DESC");
while ($showRowGeneral = mysqli_fetch_assoc($Qdaily_entriesD))
{
?>
<tr>
<td><?php echo $showRowGeneral['account_type'];?></td>
<td><?php echo $showRowGeneral['riyal'];?></td>
<td><?php echo $showRowGeneral['dollars'];?></td>
</tr>
<?php
}
我希望当我打印出每个account_type的不同网址所显示的值时。
赞:accounts.php?type = A,B或C
这就是我试过的
<?php
$Qdaily_entriesD = mysqli_query($connect, "SELECT * FROM daily_entries ORDER BY account_type DESC");
while ($showRowGeneral = mysqli_fetch_assoc($Qdaily_entriesD))
{
if ($showRowGeneral['account_type'] == 'b')
{
?>
<tr>
<td><?php echo $showRowGeneral['account_type'];?></td>
<td><?php echo $showRowGeneral['riyal'];?></td>
<td><?php echo $showRowGeneral['dollars'];?></td>
</tr>
<?php
}
}
?>
<tr><td colspan='3'><a href='?type=A'>A</a>, <a href='?type=B'>B</a> or <a href='?type=C'>C</a></td></tr>
但如何实现这一目标? 谢谢高级。
答案 0 :(得分:1)
如果您想为每一行添加一个链接:
$Qdaily_entriesD = mysqli_query($connect, "SELECT * FROM daily_entries ORDER BY account_type DESC");
while ($showRowGeneral = mysqli_fetch_assoc($Qdaily_entriesD))
{
?>
<tr>
<td><?echo $showRowGeneral['account_type'];?></td>
<td><?echo $showRowGeneral['riyal'];?></td>
<td><?echo $showRowGeneral['dollars'];?></td>
<td><a href="<?php echo 'accounts.php?type=' . $showRowGeneral['account_type']; ?>">your text</a></td>
</tr>
<?
}
答案 1 :(得分:1)
您是否尝试过使用$_GET
?
阅读本文以获取更多信息https://www.w3schools.com/php/php_forms.asp
在您的代码中,您希望像这样使用它,
if ($showRowGeneral['account_type'] == $_GET['type'])