最初の 15 件の一致を特定の英数字範囲 1 ~ 3 & AB で並べ替えようとしていますが、出力に何も得られません。MeekroDBの使用。私がここに持っているものを彼らの方法に翻訳する方法がわかりません。
$results = DB::query("SELECT substr(theme, 1, 1) as Alphabet
FROM gallery ORDER BY (CASE theme
WHEN '1%' THEN 1
WHEN '2%' THEN 2
WHEN '3%' THEN 3
WHEN 'A%' THEN 4
WHEN 'B%' THEN 5
ELSE -1
END) LIMIT 15");
$x = 0
foreach ($results as $row) {
$x++;
if ($x == 1) { // first in query
$t1 = $row['theme'];
$d1 = $row['developer'];
$th1 = $row['thumb'];
$thlg1 = $row['thumb_lg'];
}
...
}
本文のエコー例:
<img src="<?php echo($th1); ?>" data-retina="<?php echo($thlg1); ?>" alt="<?php echo($t1); ?>" />
<span><p class="hname"><?php echo($t1); ?></p>
<p class="hdev"><?php echo($d1); ?></p></span>
アップデート2:
$results = DB::query("SELECT substr(theme, 1, 1) as Alphabet, theme, developer, thumb, thumb_lg
FROM gallery ORDER BY (CASE
WHEN theme LIKE '1%' THEN 1
WHEN theme LIKE '2%' THEN 2
WHEN theme LIKE '3%' THEN 3
WHEN theme LIKE 'A%' THEN 4
WHEN theme LIKE 'B%' THEN 5
ELSE -1
END) LIMIT 15");
Update3:
$results = DB::query("SELECT substr(theme, 1, 1) as Alphabet, theme, developer, thumb, thumb_lg FROM gallery
ORDER BY (CASE Alphabet
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN 'A' THEN 4
WHEN 'B' THEN 5
ELSE 6
END)
LIMIT 15");