AlenD Posted August 8, 2011 Share Posted August 8, 2011 Hello, I'm wondering if there is a way to display text content in a single cell in mySQL in an ordered list. For instance, I have a cell named foodname, servings, ingredients under the table recipes. inside ingredients I'll put a lot of items.. can I echo them automatically in an ordered list? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 8, 2011 Share Posted August 8, 2011 Hi AlenD, You can use ORDER BY in mysql, but something tells me you want something more than this? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 Do you mean you have several items in the `ingredients` field, and want to do a list from there? is that a text field with a bunch of items? like: tomatoes, carrots, salt, rice, peas... (Are they comma separated?) if they are (comma separated), all you need to do is explode that particular field and then create your list from the resulting array, or just replace the commas with a <br />: something like: (assuming $result is the var name to fetch items from database) $list = explode(",",$result['ingredients']); foreach($list as $ingredient){ echo $ingredient.'<br />'; } or even just: echo str_replace(",","<br />",$result['ingredients']); Hope this helps Quote Link to comment Share on other sites More sharing options...
AlenD Posted August 9, 2011 Author Share Posted August 9, 2011 Thank you, I was looking for that explode function and have added <li></li> to the foreach echo. Thank you guys, it has worked perfectly. I have learned three new concepts thanks to you two. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.