gpt4 book ai didi

php - PHP上的数据显示(选择查询)

转载 作者:行者123 更新时间:2023-11-29 13:19:01 25 4
gpt4 key购买 nike

我有一个表,其中包含:

transaction_id | the_pet | name_of_the_owners
1 dog shiela
2 dog ben
3 dog alice
4 cat jonathan

根据我的查询:

$query="select * from table ORDER BY name_of_the_owner limit 5";
$r=mysqli_query($query);
while ($row=mysqli_fetch_array($r)) {

echo "<tr>";
echo "<td><a href='../php/ownersname.php?the_pet=".$row['the_pet']."'>".$row['the_pet']."</a></td>";
echo "</tr>";
}

但是,当我使用 $query 时,它显示表中的所有数据。我需要的是这样的:

     the_pet
dog (hyperlink)
cat (hyperlink)

因此,每当我单击超链接时,所有者的名称就会显示在另一个页面中

点击时的狗

name_of_the_owners
shiela
ben
alice

我已经用过

$query = "SELECT MAX(transaction_id) as transaction_id, the_pet GROUP BY the_pet, name_of_the_owners;

但是当我单击超链接时,它没有显示所有者。 :(

最佳答案

所以,如果我理解正确的话,你不想显示重复项,对吧?

我认为最好的方法是将您的选择查询更改为

$query = "SELECT DISTINCT the_pet FROM table";

如果您不想这样做,您可以过滤数组中的重复项

像这样:

$arr = array('php','jsp','asp','php','asp');
$unique = array_unique($arr);
print_r($dups);

两者都可以解决问题!

关于php - PHP上的数据显示(选择查询),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21104466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com