I am driving bmw 323i E90 2006 with 196000km. When I'm starting the engine sometimes idling is so bad you find the whole car vibrating then when you put it on a drive gear it does move but not smoothly you can hear the sound even from the outside and the smell of petrol as well too sometimes when you come to a stop engine goes off or if it's on you find the Rev counting going up and down just above 1 but sometimes it can go smoothly as if nothing is wrong. So my question is what causes it to do that? And how can I solve the problem
This is often times related to what is called an idle air control valve which controls the air/fuel mixture at idle speed. When this is not working properly, this can cause the car to run either too rich (too much fuel - maybe causing the fuel smell) or too lean which means not enough fuel.
Either scenario can cause the car to run very rough like you have noticed. I would recommend having a certified expert, such as one from YourMechanic, take a look at the car to diagnose the misfire firsthand and help you fix it accordingly.