gpt4 book ai didi

php - 如何在php中显示B列中具有相同值的A列的所有结果

转载 作者:可可西里 更新时间:2023-11-01 07:56:04 25 4
gpt4 key购买 nike

我有这样的数据库

column A        Column B

2015-11-25 session 1
2015-11-26 session 1
2015-11-27 session 1
2015-11-28 session 2

我要显示喜欢

Next session 1 is on - 25 Nov 2015, 26 Nov 2015, 27 Nov 2015

我试过 GROUP BY 列 B 但它只返回一个,第一个值。即 2015 年 11 月 25 日。

<?php
$sql = mysql_query("select * from table GROUP BY column B HAVING COUNT(*) > 1 order by column A ASC");
while($data=mysql_fetch_array($sql)){
?>

Next <?=$data['column B']?> Is On <b><?=date("d F Y",strtotime($data['coulmn A']));?>
<?}?>

最佳答案

试一试:

 <?php
$sql = mysql_query("select ColumnA, ColumnB from table GROUP BY columnB, ColumnA HAVING COUNT(*) > 1 order by column A ASC");
while($data=mysql_fetch_array($sql)){
?>

Next <?=$data['columnB']?> Is On <b><?=date("d F Y",strtotime($data['coulmnA']));?>
<?}?>

关于php - 如何在php中显示B列中具有相同值的A列的所有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33624586/

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