1

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

This my array.

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

I need this result

               [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                             
                            )
                     )                
                )

how i do these [number_stitch] ?

1 Answers1

1

Try

select s.*, @rowcount:=@rowcount+1 ‘number_stitch’ from stitch s, (SELECT @rowcount:=0) r order by id;
Kami
  • 19,134
  • 4
  • 51
  • 63