哎这个疑难问题all.i'm新手在表中的结果这样的数据:组合正则表达式和PHP还是不行
item range_code class
red 123x0001-123x0500 A
blue 123x0021-123x0100 //if null read zero
green 123x0001-123x0300 b
我要像结果:
item qty S A B C
red 500 0 1 0 0
blue 80 0 0 0 0
green 300 0 0 1 0
我已尝试此代码,但仍然不起作用:
$sql= 'SELECT item, range_code as qty, class FROM result GROUP BY item, qty';
$result=mysql_query($sql);
while ($row=mysql_fetch_assoc($result)){
preg_match_all('/\d+(?=-|$)/g',$row['qty'],$matches);
echo intval($matches[0][1])-intval($matches[0][0])+1;
}
我仍然为这个问题混淆。 请帮忙..
您将不得不解释您的预期输出值来自哪里。 – 2010-08-18 03:15:28
即使我必须对评论+1。 – sberry 2010-08-18 03:31:49