With any health concerns you should always seek professional medical advice - because here on TSR we are for the most having un-educated guesses and know nothing about you as an individual or your health.
The reasons for alternating constipation and diarrhoea are wide and varied, the majority of the time the reasons are minor, related to a slightly different food or bacteria. A lot of the time there are a lot of natural variations in poo consistency and frequency. A lot of poo and gut problems are sometimes unwittingly caused by eating a diet high in processed foods coupled with a lack of water intake.
You can help yourself now and for the future by being kind to your gut and by making changes to your diet longterm. This is not directed qualified medical advice but common sense.
The information provided here assumes you are not allergic or intolerant to particular foods and that you do not have to stick to a rigid diet for medical reasons. Follow professional medical advice if you are having any gut issues.
Make changes to your diet gradually. If you eat a very low residue diet, with very few vegetables or few fibre rich carbohydrates you will be constipated. If you eat lots of vegetables which contain lots of soluble fibre your poo will be soft and easily expelled. You won't need to fret over not having a poo for a long time. Constipation is a Western based disease. It is inflicted on many children (& adults) through ignorance. Children can end up in a great deal of pain and distress caused in the main by a diet based on white bread, white pasta, white rice, chocolate, sweets and biscuits. Sometimes constipation can be caused by dehydration by a lack of water intake.
Focus on eating foods with a high fibre content. Lots of potatoes, root veg, boiled, baked etc, baked beans, peas, sweetcorn, vegetables in soups or casseroles (particularly carrots), wholemeal breads, wholemeal rice, wholemeal pasta, fruits - particularly apples and bananas. Try to avoid all highly processed foods, white bread products, white flour, processed biscuits (sweet & savoury), chocolate, sweets, crisps etc where there is a lot of salt, chemicals and additives and little nutritional or fibre value.
Make sure you drink lots of water. Avoid constipation at all costs. Constipation is linked to diverticulosis, pain, haemorrhoids through straining away, and in extreme cases constipation can create to a complete blocked bowel. Constipation is often self treated by taking laxatives which can create diarrhoea, which is then self treated by medication causing constipation. Your poor gut - you crucify it. Care of your gut is your bodies immune system's route to good health. Love it, nurture it and fill your gut with fruit, vegetables, pulses and oats. Constipation is one of the most under reported health scandals in the 21st Century. It should not exist with the amazing education we all have access to.