GROUP BY功能不起作用

时间:2017-01-31 08:23:10

标签: php mysql wamp

更新wamp php 5.6和windows 10后,GROUP BY功能无法正常工作,在Windows 7和之前的wamp工作正常。是代码中的错误还是wamp或windows或..,否则?

$sql = "SELECT * FROM user JOIN messages ON userID = usertwo WHERE userone = $user GROUP BY usertwo ORDER BY MAX(date) DESC LIMIT 10";
                 $result = $con->query($sql);

                 if ($result->num_rows > 0) {
                 // output data of each row
                 while($row = $result->fetch_assoc()) {

---不工作

但没有GROUP BY和()MAX正常工作

$sql = "SELECT * FROM user JOIN messages ON userID = usertwo WHERE userone = $user  ORDER BY date DESC LIMIT 10";
                 $result = $con->query($sql);

                 if ($result->num_rows > 0) {
                 // output data of each row
                 while($row = $result->fetch_assoc()) {

1 个答案:

答案 0 :(得分:0)

谢谢你,你最好,在新的PHP 5.6中你必须选择列,不再使用*,而不是以前版本中的work湖...

$ sql =“SELECT userID,firstname,lastname FROM user JOIN messages ON userID = usertwo WHERE userone = $ user GROUP BY usertwo ORDER BY MAX(date)DESC LIMIT 10”;                      $ result = $ con> query($ sql);

                 if ($result->num_rows > 0) {
                 // output data of each row
                 while($row = $result->fetch_assoc()) {
感谢:Farkie,krishn patel ......