简体   繁体   English

上传图像以及如何使用GROUP BY和MAX()在SQL中获取图像

[英]Uploading Images and how to get that image inside the SQL using GROUP by and MAX()

$result = mysql_query("SELECT * FROM photos WHERE accountID = '{$accID}' GROUP BY album_name ORDER BY photo_number DESC");
if(mysql_num_rows($result) != 0) {
    while( $row = mysql_fetch_array($result) ) {
        echo "<div class=\"myPhotos\"><img title='Album: {$row['album_name']}' src=\"images/profile/".$row['photo_link']."\"/></div>";
    }
}else{
    echo "No Album Created";
}

My Intension: is to get the HIGHER 'photo_number' value, while I am also grouping them by their own respective 'album_name' however my $result cant recognize the TOP/HIGHER 'photo_number'(AUTO INCREMENT attribute) how could I recognize the HIGHER 'photo_number' ? 我的意图:是要获得HIGHER'photo_number'值,同时我还将它们按各自的'album_name'分组,但是我的$ result无法识别TOP / HIGHER'photo_number'(AUTO INCREMENT属性),我怎么能识别HIGHER 'photo_number'?

they said that I need to use MAX(photo_number) but, how to code that MAX() syntax?...I hope that you can help me in this problem... 他们说我需要使用MAX(photo_number),但是,如何编码MAX()语法?...希望您能在这个问题上对我有所帮助...

It isn't perfectly clear but I guess you want the highest photo number for each album name and then to sort by that number. 这还不是很清楚,但是我想您想要每个相册名称的最高照片编号,然后按该编号排序。 If that's the case you'll want something like... 如果是这种情况,您会想要类似...

SELECT album_name,
       MAX(photo_number) AS highest_photo_number
    FROM photos
    WHERE accountID = (whatever)
    GROUP BY album_name
    ORDER BY highest_photo_number;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM