- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这是我第一次使用 PHP 或 SQL。
我正在制作一个简单的网站,其中托管应用程序及其名称、作者、版本、描述等。PHP 脚本从我创建的 MySQL 数据库中获取此信息。每个应用程序都有一个分配给它的唯一标识符。多个版本将重复使用相同的标识符。
我让它显示只有一个版本的条目。
然而...
当应用程序的更新版本发布时,我希望它在最新版本旁边的下拉列表中列出旧版本(只是链接到旧版本链接的版本号)。我创建数据库时假设我会想出一种很好地显示它的方法,因此当我将应用程序的更新版本添加到数据库时,我将未更改的内容留空(如名称、作者、描述) , 给了它与旧版本相同的标识符,只添加了新版本号和新版本的文件名。参见 here举个例子。
然而,我假设错了。
我不知道如何进行。我有一个问题:
SELECT * FROM apps WHERE identifier IN ( SELECT identifier FROM apps GROUP BY identifier HAVING count(*) > 1)
但是,这只会选择所有具有重复“标识符”的条目。我不知道如何通过循环运行它,以回显旧条目的描述/名称但回显较新条目的版本号/链接(同时还能够为我的下拉菜单回显旧版本号/链接)。哦,而且它不会将名称/描述/等分配给具有重复标识符但与其他应用程序标识符不同的应用程序。抱歉,这很难解释。
我当前的循环是:
$result=mysqli_query($connection,$query);
$num=mysqli_num_rows($result);
$i=0;while ($i < $num) {while ($row = mysqli_fetch_array($result)) {
// do stuff (echo)
} ;$i++;};
只是分别回显条目,一个是旧版本,一个是新版本(不显示描述、名称或作者)。
我应该如何进行?
最佳答案
这样的事情怎么样:
您从表中选择所有数据,按标识符 排序,然后按版本 排序。查询是这样的:
-- ↓ orders data by identifier, thereby 'grouping' together records with the same identifier
SELECT * FROM apps ORDER BY identifier, version DESC
-- ↑ orders each 'group' by version number descending - highest / 'newest' first
然后,根据这些数据,您可以在 PHP 中创建一个数组结构,这将使您能够轻松地遍历数据。类似于以下内容:
$result = mysqli_query($connection,$query);
$apps = array(); // Create apps array
while ($row = mysqli_fetch_array($result)) {
// Assign the Name, Description, Author of the row
// These will be blank until the last (oldest version) which has these values
// $app[$row[1]] will create a key for each identifier or use the existing one
$apps[$row[1]]["name"] = $row[2];
$apps[$row[1]]["description"] = $row[3];
$apps[$row[1]]["author"] = $row[4];
// If there is no current version stored
if(empty($apps[$row[1]]["current_version"])){
$apps[$row[1]]["current_version"]["version"] = $row[5];
$apps[$row[1]]["current_version"]["source"] = $row[6];
$apps[$row[1]]["current_version"]["filename"] = $row[7];
} else { // If not, this means this row is an older version
$v = array(
"version" => $row[5],
"source" => $row[6],
"filename" => $row[7],
);
$apps[$row[1]]["older_versions"][] = $v; // Add the array to the older_versions array
}
}
这会产生以下数组结构:
Array
(
[vitashell] => Array
(
[name] => VitaShell
[description] => VitaShell is an alternative replacement...
[author] => TheFloW
[current_version] => Array
(
[version] => 0.86
[source] => http://www.example.com/link/version/0_86
[filename] => vitashell_0_86.vpk
)
[older_versions] => Array
(
[0] => Array
(
[version] => 0.8
[source] => http://www.example.com/link/version/0_8
[filename] => vitashell_0_8.vpk
)
)
)
[identifier] => Array (...)
)
然后,您可以使用几个 foreach
循环遍历 $apps
数组,根据需要打印出数据。
我做了一个打印数据的简单例子。出于显示目的,我向数据集添加了一些虚拟行:
<?php foreach($apps as $app){ ?>
<div class="app">
Name: <?php echo $app["name"]; ?><br />
Description: <?php echo $app["description"]; ?> <br />
Author: <?php echo $app["author"]; ?> <br />
Version: <a href="<?php echo $app["current_version"]["source"]; ?>"><?php echo $app["current_version"]["version"]; ?></a> <br />
<?php if(!empty($app["older_versions"])){ ?>
Older Versions:
<select name="older_versions">
<?php foreach($app["older_versions"] as $version){ ?>
<option value="<?php echo $version["source"] ?>"><?php echo $version["version"]; ?></option>
<?php } ?>
</select>
<?php } ?>
</div>
<hr>
<?php } ?>
它创建:
注意:“TIMSTUFF”只有 1 个版本,因此没有针对旧版本的下拉列表
关于php - 如何处理 PHP/SQL 支持的文件镜像上的多个文件版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39287815/
我需要将 OCI 镜像 list 转换为 Docker v2.2 镜像格式,反之亦然。但我找不到两者之间的任何区别,是否有任何实际区别或它们相同? 最佳答案 Docker 镜像 list V 2,模式
LNMP 是代表 Linux 系统下的 Nginx、Mariadb、PHP 相结合而构建成的动态网站服务器架构。下面使用docker制作分布式lnmp 镜像。 1、docker 分布式 lnmp
你好,我创建了一个基础镜像;但是,每当我运行 docker build . 时,我都看不到成功构建 我的 docker 文件 FROM centos:7 ARG user=john ARG home=
我想要我的 iPhone 应用程序中有一个功能,可以将图像转换为类似镜像的方式。 就像如果有一个左手举起的人的图像,那么转换后的图像必须有右手举起的同一个人。 任何代码或链接将不胜感激 预先感谢您的帮
我们希望将一个Elasticsearch集群放置在kubernetes集群的顶部(当前有2个节点,但是我们计划增加它)。 是否可以通过使集群中的每个节点包含相同数据的方式配置elasticsearch
我试图了解 docker 如何在文件系统上存储图像和图层。构建图像时,图层出现在 /var/lib/docker/image/overlay2/layerdb 中,图像出现在 /var/lib/doc
所以我最近开始使用 docker,因为我认为让我的网站 dockerised 会很好。我有一个 super 简单的 docker-compose.yml 文件,其中仅包含 wordpress:late
我有一个 docker 镜像,叫它 dockerimage/test。每次我更新它时,我都会增加一个标签,所以 dockerimage/test:1、dockerimage/test:2 等等。 当我
我开始使用 Docker,我发现我可以将主图像存储库放在不同的磁盘上(符号链接(symbolic link)/var/lib/docker 到其他位置)。 但是,现在我想看看是否有办法将它拆分到多个磁
显然应用程序打包和部署似乎有两种做法 创建 Docker 镜像并部署它 从头开始构建和部署应用程序。 我对如何使用选项 1) 感到困惑。前提是你获取一个 docker 镜像并在任何平台上重复使用它。但
我有一个 UIView具有透明背景和一些按钮。我想捕获 View 的绘图,将其缩小,然后在屏幕上的其他位置重新绘制(镜像)它。 (在另一个 View 之上。)按钮可以更改,因此它不是静态的。 最好的方
我正在为一个项目编写测试,我想测试和验证一个 docker 镜像构建。但我不想推送图像。 我希望图像构建在 CI(如 taskcluster)上并运行测试。 最佳答案 您需要使用 taskcluste
我想复制每个 html 页面中的代码,同时添加一些更改: 例子: Any text (even if includes :., 输出: Any text (even if includes :.,
我使用三星 ARM Cortex A9 Exynos4412 板。我在板上启动“linux + Qt”img。但是板上没有包管理器,也没有 make 、 gcc 命令。在/bin 文件中有文件 Bus
是否有可能以某种方式设置一个 git 存储库,该存储库像通常的 --mirror 一样用于 pull 入它,但在将从推送到另一个存储库时没有强制? 最佳答案 您可以像这样添加 --no-force 来
背景 最近在巡检过程中,发现harbor存储空间使用率已经达到了80%。于是,去看了一下各项目下的镜像标签数。发现有个别项目下的镜像标签数竟然有好几百个。细问之下得知,该项目目前处于调试阶段
以下均在centos 7进行的操作 docker安装 ? 1
我知道如何删除 N 天前创建的旧 Docker 镜像。 See here 但我真正想做的是删除过去 N 天未使用的旧 Docker 镜像。 目标是保留经常使用的图像,即使在我进行清理时没有容器实际使用
我有一个自定义的 docker 镜像,已经构建好了。没有可用的 Dockerfile。在容器内部,可以使用自定义用户,而不是 root,比如 test。此用户已附加到组 test。这是容器的默认用户。
我有一个开发数据库,我想将其提交到 docker 镜像中,然后推送到私有(private)存储库并用于本地开发和 CI 构建。 数据库保存为SQL备份,我可以通过将备份文件映射到官方镜像的/doc
我是一名优秀的程序员,十分优秀!