[英]Sorting numbers between x.00 x.99 and so on from database
As the title what I'm trying to do is get numbers from database which I already do display them from descending order which I do. 作为标题,我要尝试的是从数据库中获取数字,而我已经按照自己的降序显示了它们。 Patch numbers are in format X.XX so 2.01 2.05 2.22 and so on I want to label numbers between 2.00 - 2.highest one as Season 2 so Season 2 then patches like 2.99 2.85 2.04 2.00 etc.
补丁号的格式为X.XX,所以2.01 2.05 2.22,依此类推,我想将第2.00到2之间的数字标记为第2季,所以第2季度再打补丁,例如2.99 2.85 2.04 2.00等。
My PHP: 我的PHP:
foreach($patches as $patch)
{
if(substr($patch, -2)=="00"){
echo 'Season '.substr($patch, 0,1).'<br>';}
echo '<a href="../index.php?Patch_No='.$patch.'" class="patches">'.$patch.'</a><br/>';
}
And my query: 而我的查询:
$patches = $conn->prepare("SELECT Patch_No FROM info ORDER BY Patch_No DESC");
$patches->execute();
$patchesresult = $patches->get_result();
while($data1 = $patchesresult->fetch_assoc()){
$patch[$i]=$data1["Patch_No"];
$i+=1;
}
I probably have to check what is currently the highest patch so It could write first title Season XX 我可能必须检查当前最高的补丁程序,这样它才能写第一个标题Season XX
UPDATE - my 2D array: 更新-我的2D数组:
$i=$j=0;
foreach($patches as $patch)
{
if($j!=0){
if(substr($patch, 0,1)!=substr($patch_array[$i][$j-1],0,1)){
$i+=1;
$j=0;
}
}
echo '$patch_array['.$i.']['.$j.'] '.$patch_array[$i][$j]=$patch.' substr$patch='.substr($patch, 0,1).' substr_previous: '.substr($patch_array[$i][$j-1],0,1).'<br/>';
$j+=1;
}
The array saves under [$i][$j] $i - is for patches with the same first number so 2.xx 2.xx 2.xx will be under the same $i and $j are for endings .01 .03 .04 so [0][1] [0][2] [0][3] - {2.50 2.14 2.01} [1][1] [1][2] [1][3] - {3.03 3.10 3.02} 数组保存在[$ i] [$ j] $ i下-用于具有相同第一个数字的补丁,因此2.xx 2.xx 2.xx将在相同的$ i下,$ j用于结尾.01 .03约0.04,所以[0] [1] [0] [2] [0] [3]-{2.50 2.14 2.01} [1] [1] [1] [2] [1] [3]-{3.03 3.10 3.02 }
Now I need to figure out displaying bit second loop 现在我需要弄清楚显示第二个循环
I changed up some syntax and variable names to make it a bit less confusing, but I think this is what you are going for. 我更改了一些语法和变量名称,以减少混乱,但是我认为这是您要的。 Also changed (improved) your query syntax.
还更改(改进)了您的查询语法。
$patches = $conn->prepare("SELECT Patch_No FROM info ORDER BY Patch_No DESC");
$patches->execute();
$patches->bind_result($patchNum);
$episodes=array();
while($patches->fetch_assoc()){
//build 1d array
$data=array($patchNum, substr($patch,0,1));
//push 1d array to array of arrays (2d array)
$episodes[]=$data;
echo '<a href="../index.php?Patch_No='.$patchNum.'"
class="patches"
>'.$patch.'</a><br/>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.