1

$sql=sprintf("SELECT * FROM stitch);

これは私の配列です。

       [stitch] => Array
                    (
                        [0] => Array
                            (
                                [id] => 7, 
                                 [name] => Sew buttonhole to front fly
                            )
                        [1] => Array
                            (
                                [id] => 8,
                                [name] => Sleeve hem    
                            )
                     )                
                )

この結果が必要です

               [stitch] => Array
                    (
                        [0] => Array
                            (
                                [id] => 7,
                                [name] => Sew buttonhole to front fly  
                                [number_stitch] => 1
                     )
                        [1] => Array
                            (
                                [id] => 8,
                                [name] => Sleeve hem 
                                [number_stitch] => 2                             
                            )
                     )                
                )

これらの [number_stitch] を行うにはどうすればよいですか?

4

1 に答える 1

1

試す

select s.*, @rowcount:=@rowcount+1 ‘number_stitch’ from stitch s, (SELECT @rowcount:=0) r order by id;
于 2012-11-08T16:15:24.373 に答える