gpt4 book ai didi

php mysql 选择仅匹配列

转载 作者:行者123 更新时间:2023-11-29 08:37:21 25 4
gpt4 key购买 nike

          Mysql Database-

id | username | folder_name |
1 | ashly | Folder |
2 | ashly | |
3 | ashly | |
4 | ashly | Folder |
5 | ashly | Folder |
6 | ashly | Folder 1 |
7 | ashly | Folder 2 |


$sql = mysql_query("SELECT `id`, `username`, `title`, LEFT(`description`, 90) as `description`, `file`, `code`, `folder_name`, `type`, `size`, `date` FROM `files` WHERE `username` = '$userfile' AND `folder_name` > '' ORDER BY `id` DESC LIMIT 1, 5");


while ($query_row = mysql_fetch_array($sql2)) {
$filefolder = $query_row['folder_name'];
$filetitle = $query_row['title'];
$filecode = $query_row['code'];
$filedesc = $query_row['description'];
$filefile = $query_row['file'];
$filesize = $query_row['size'];
$filedate = $query_row['date'];
$filetype = $query_row['type'];

//这里我循环获取结果

        if (empty($filefolder) === false) {
echo "" . $filefolder . "<div id='imageshowsearch'><div id='linkstyle'><strong><a href='http://localhost/edu/1111111111111/userdownload.php?code=". $filecode . " '><img src='files/thumbs/" . $filecode . "/" . $filefile . "' alt=" . $filetitle . ">" . $filetitle . "</strong></div></a></div>";

//here print result
}
}

我无法仅显示一次folder_name。文件夹中有 5 个图像。|当我循环它以获得 mysql 结果时。

     Result:   

folder | folder | folder | folder 1 | folder 2
here is image | here is image | here is image | here is image | here is image

I wonna get this result:

folder |
here is image | here is image | here is image |

folder 1 |
here is image |

folder 2 |
here is image |

我不知道。如何仅显示一次文件夹名称,并在文件夹名称下显示某个文件夹中最多 5 个图像。只是我不会对每张图像重复文件夹名称。我必须将文件夹名称、文件夹图像和用户图像分组。我的问题只是这些文件夹名称重复...感谢您对我写的支持,因为网站不允许我发布我的问题“更多代码无需解释”

最佳答案

您可以使用以下方式。希望它对你有用。

$sql = mysql_query("SELECT DISTINCT `folder_name` FROM `files` WHERE `username` = '$userfile' AND `folder_name` > ''");
while ($row = mysql_fetch_array($sql)) {
$folder== $row['folder_name'];

$sql2 = mysql_query("SELECT `id`, `username`, `title`, LEFT(`description`, 90) as `description`, `file`, `code`, `type`, `size`, `date` FROM `files` WHERE folder_name`='$folder' ORDER BY `id` DESC LIMIT 1, 5");

//Here you can echo $folder i.e, folder name and then all its image
while ($query_row = mysql_fetch_array($sql2)) {
$filetitle = $query_row['title'];
$filecode = $query_row['code'];
$filedesc = $query_row['description'];
$filefile = $query_row['file'];
$filesize = $query_row['size'];
$filedate = $query_row['date'];
$filetype = $query_row['type'];
}

}

祝你好运。

关于php mysql 选择仅匹配列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14909090/

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