循环捕获新的百数
我在数据库中找到了公交车号码列表。此处示例:
route_id,route_short_name,route_long_name,route_type,route_color,route_text_color
1,1,Victoria / Churchill,3,A32638,FFFFFF
2,2,Tiffin / St-Georges,3,A32638,FFFFFF
99,99,Saint-Bruno,3,A32638,FFFFFF
100,100,Ile-Des-Soeurs,3,A32638,FFFFFF
106,106,Secteur B / Victoria,3,A32638,FFFFFF
199,199,Seigneurial / Grand Boulevard,3,A32638,FFFFFF
818,T18,Taxi - Aéroport,3,A32638,FFFFFF
893,T93,Taxi - De Mortagne - Du Boisé - Ch. De Touraine,3,A32638,FFFFFF
我们将使用route_id(第一列)。
这是我的问题。我怎样才能抓住新的一百个?上面的预期结果是
1 to 99
100 to 199
818 to 893
我几乎总是能找到问题的答案,但这一次..我真的没有。我这样做了,但效果不佳:
# Creating the array
$Routes = array();
$Quick = array();
# Array launching
$F_D = -1;
$i=0;
while($Assoc_Routes = mysql_fetch_assoc($Query_Routes)){
# Array
$Routes[] = $Assoc_Routes;
$Digit_Length = strlen($Assoc_Routes['route_short_name']);
switch($Digit_Length){
case 1 : $Digit = '00'.$Assoc_Routes['route_id'][0]; break;
case 2 : $Digit = '0'.$Assoc_Routes['route_id'][0]; break;
default: $Digit = $Assoc_Routes['route_id'][0]; break;
}
if($Digit[0] != $F_D){
# Count
$i++;
# Avoid the first one
if($i > 1){
$Quick[$i-1]['g'].= ' à '.($Assoc_Routes['route_id']-1);
}
$Quick[$i] = array('g' => 'Groupement '.$Assoc_Routes['route_id']);
}
$F_D = $Digit[0];
}
感谢您的帮助。
I got a list of bus number in my database. Sample here :
route_id,route_short_name,route_long_name,route_type,route_color,route_text_color
1,1,Victoria / Churchill,3,A32638,FFFFFF
2,2,Tiffin / St-Georges,3,A32638,FFFFFF
99,99,Saint-Bruno,3,A32638,FFFFFF
100,100,Ile-Des-Soeurs,3,A32638,FFFFFF
106,106,Secteur B / Victoria,3,A32638,FFFFFF
199,199,Seigneurial / Grand Boulevard,3,A32638,FFFFFF
818,T18,Taxi - Aéroport,3,A32638,FFFFFF
893,T93,Taxi - De Mortagne - Du Boisé - Ch. De Touraine,3,A32638,FFFFFF
We will be working with route_id (first column).
Here is my question. How can I catch a new hundred ? The expected results from above will be
1 to 99
100 to 199
818 to 893
I am almost always finding the answer to my question but this time.. I really don't. I did this but this ain't working well :
# Creating the array
$Routes = array();
$Quick = array();
# Array launching
$F_D = -1;
$i=0;
while($Assoc_Routes = mysql_fetch_assoc($Query_Routes)){
# Array
$Routes[] = $Assoc_Routes;
$Digit_Length = strlen($Assoc_Routes['route_short_name']);
switch($Digit_Length){
case 1 : $Digit = '00'.$Assoc_Routes['route_id'][0]; break;
case 2 : $Digit = '0'.$Assoc_Routes['route_id'][0]; break;
default: $Digit = $Assoc_Routes['route_id'][0]; break;
}
if($Digit[0] != $F_D){
# Count
$i++;
# Avoid the first one
if($i > 1){
$Quick[$i-1]['g'].= ' à '.($Assoc_Routes['route_id']-1);
}
$Quick[$i] = array('g' => 'Groupement '.$Assoc_Routes['route_id']);
}
$F_D = $Digit[0];
}
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个新变量来跟踪您所在的组:
然后将您的route_id与currentGroup进行比较,看看它是否在其groupSize内:
Make a new variable that tracks which group you are in:
Then compare your route_id to the currentGroup to see if it's within its groupSize:
不确定您希望输出的形式是什么,但这是我采取的方法:
Not sure in what form you want the output to be, but here's the approach I'd take: