I want to have a database of recipes which I can call to a page. I would like the output to be like that below followed by the method What is the best way to achieve this. I don't want to start something and find I have the wrong method. Is is possible to put information into a mysql database formatted as I want it to be displayed when extracted. Apologies if this is a stupid question, I just can't think how to do this. Cheers Harlequeen
There's two ways in php... use the nl2br function, which replaces newline characters with <br />'s or do it yourself with str_replace.
This is very complicated, an impossible with PHP or really any other programming language. The script has to know from Impossible! unless your computer/web server has advanced AI (artificial intelligence) which I assume you don't have.
I'm not sure what to make of this, there seems to be one reply boiling the question down into its simplest form and then one reply looking at how to teach a computer to cook. I think I'll go for something in the middle. There is no reason why you can't store formatted text in a database. How you do that is entirely up to you. You could store both the ingredients and the method in one field of your database or you could have you ingredients in one and the method in another. You could have each ingredient in a seperate entry in a table. If all you want is to display the recipes on the page it isn't going to make much difference. If you want to allow your users to search for recipes then it will require more thought. If I was setting the system up I would tend towards seperating the method from the ingredients and having each ingredient as a seperate entry in the database. Perhaps something like id | quantity | unit | ingredient Code (markup):
I don't think you need to go that complicated. You won't need to sort the ingredients, quantity etc. I'd suggest just create a table recepies (or whatever) with these fields: id (int) | ingredients (blob/text) | method (blob/text) Code (markup): Save the ingredients and method as text formatted in a textarea. Use nl2br as suggested by MrX and save the ingredients and method in db. Then simply pull it and display on the page. You can be all fancy and have different tables for ingredients and method, then save each ingredient and method as a seperate row and point them to a recepie_id which is located in another table. But I don't think you'll need it. My $0.02!
Thanks everyone, I am going to try the nl2br method on the weekend. It doesn't need to be too fancy, so I'll give it a go. Cheers Harlequeen