gpt4 book ai didi

PHP 通过唯一 ID 分组进行编号

转载 作者:行者123 更新时间:2023-11-29 10:51:49 24 4
gpt4 key购买 nike

我想自动编号,但按用户组

查询:

$query = "select distinct(DATE_FORMAT(a.in_time, '%Y%m%d')) as in_time, a.user_id, a.notes, b.nama from attendance a left join dat_login b on(a.user_id=b.ID) where DATE_FORMAT(a.in_time, '%Y')='2017' and DATE_FORMAT(a.in_time, '%M')='April' and id_shop!=2 order by b.nama asc";
$querynm = "select distinct(b.nama) as nama from attendance a left join dat_login b on(a.user_id=b.ID) where DATE_FORMAT(a.in_time, '%Y')='2017' and DATE_FORMAT(a.in_time, '%M')='April' group by b.nama order by b.nama asc";
$stid = mysqli_query($conn, $query) or die (mysqli_error($conn));
$stnm = mysqli_query($conn, $querynm) or die (mysqli_error($conn));

结果:

$alphabet_start = 'A';
while ($data = mysqli_fetch_assoc($stid)) {
$data['user_id'] += 1;
$no_cell = 11;
echo $data['nama'] . " ";
echo $data['user_id'] . " ";
if ($data['notes']=="") {
echo chr(ord("A") + date('d', strtotime($data['in_time']))) . $no_cell . " - " . chr(ord("A") + date('d', strtotime($data['in_time']))) . ". " . "Masuk <br>";
} else if ($data['notes']=="S") {
echo chr(ord("A") + date('d', strtotime($data['in_time']))) . $no_cell . " - " . chr(ord("A") + date('d', strtotime($data['in_time']))) . ". " . "Sakit <br>";
} else if ($data['notes']=="L") {
echo chr(ord("A") + date('d', strtotime($data['in_time']))) . $no_cell . " - " . chr(ord("A") + date('d', strtotime($data['in_time']))) . ". " . "Libur <br>";
}
$alphabet_start++;
$no_cell++;
$data['user_id']++;
}

但是,值显示如下:

enter image description here

我希望值显示如下:

enter image description here

正如您所看到的,下一个名称中的数字正在变化,该怎么办?抱歉我的语法不好。先谢谢了:)

最佳答案

你的代码有点令人困惑,但我想我明白你的意思。你可以这样做:

$alphabet_start = 'A';
$userID = "";
$cells = array();
$cellNum = 11;

while ($data = mysqli_fetch_assoc($stid)) {
$data['user_id'] += 1;

if (in_array($data['user_id'], $cells)) {
$no_cell = $cellNum;
} else {
$no_cell = ($cellNum += 1);
$cells[] = $data['user_id'];
}

echo $data['nama'] . " ";
echo $data['user_id'] . " ";
if ($data['notes'] == "") {
echo chr(ord("A") + date('d', strtotime($data['in_time']))) . $no_cell . " - " . chr(ord("A") + date('d', strtotime($data['in_time']))) . ". " . "Masuk <br>";
} else if ($data['notes'] == "S") {
echo chr(ord("A") + date('d', strtotime($data['in_time']))) . $no_cell . " - " . chr(ord("A") + date('d', strtotime($data['in_time']))) . ". " . "Sakit <br>";
} else if ($data['notes'] == "L") {
echo chr(ord("A") + date('d', strtotime($data['in_time']))) . $no_cell . " - " . chr(ord("A") + date('d', strtotime($data['in_time']))) . ". " . "Libur <br>";
}
$alphabet_start++;
$no_cell++;
$data['user_id']++;
}

关于PHP 通过唯一 ID 分组进行编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43602190/

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