-2
distID   distName   regID
1        Khulna      1
2        Shatkhira   1
3        Bagerhat    1
4        Pirojpur    1
5        Barishal    2
6        Barguna     2
7        Patuakhali  2
8        Bhola       2
9        Jhalokathi  2

您好我有上表,可以正常显示数据。我需要在输出中对 regID 字段进行分组。我怎样才能做到这一点?下面是我的php代码。

<?php
            include("db.php");


            $result=mysql_query("SELECT * from district d inner join region r on d.regID=r.regID");
        //  $result1=mysql_fetch_array(mysql_query("SELECT * FROM district"));
               // echo '<pre>';
                //print_r($result);

            while($test = mysql_fetch_array($result))
            {   //print_r($test);
                $id = $test['distID'];  
                echo "<tr align='center'>"; 
                echo"<td><font color='black'>" .$test['distName']."</font></td>";
                echo"<td><font color='black'>" .$test['regName']."</font></td>";
                echo"<td> <a href ='view.php?distID=$id'>Edit</a>";
                echo"<td> <a href ='del.php?distID=$id'><center>Delete</center></a>";

                echo "</tr>";
            }
            mysql_close($conn);
            ?>
4

3 回答 3

-1

在查询末尾添加 GROUP BY reqID。

但是,它只会返回 1 和 2。

于 2013-07-03T04:45:30.113 回答
-1

你可以简单地添加GROUP BY任何你想要的,

$result=mysql_query("SELECT * from district d inner join region r on d.regID=r.regID GROUP BY `regID`");
于 2013-07-03T05:28:40.870 回答
-1
$result=mysql_query("SELECT * from district d inner join region r on d.regID=r.regID GROUP BY r.regID");
于 2013-07-03T04:46:49.183 回答