Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the best way to do this.

Status
Not open for further replies.

offdarock

Programmer
Sep 8, 2003
132
CA
I have a section on my site for recipies
I am converting it to coldfusion and I want users to enter their favorite recipies

when it comes to the ingredients, some will have 3 things, some may have 20 things...I want the user to enter the items in a text box and when the recipie is displayed..I want at ingrediends displayed in BULLET form...with one indredient per bullet.

Now I dont want to create 20 fiends and call them ingredient1, ingredient2 and so on, just one field caled ingredients...is is possible...
 
It is possible, but doing so may be a 'recipe' for disaster (sorry, couldn't hold back on the pun)

What you could do is, instead of using a text field for the recipe entry, you could use a textarea field <TEXTAREA WRAP=OFF NAME=INGREDIENT>. This will allow the user to enter multiple text lines.

Then, inform the user to use a carriage return (enter/return key) when he/she needs to add a new ingredient.

Store the INGREDIENT field (form.ingredient) value in your database.

When you cfoutput the field, you can replace the carriage returns that the user intially entered with a list item (<li>).

If I remember correctly, the ascii values for a carriage return is (13) & (10). If I'm correct, then your coldfusion code for the replace will be something like:

<cfset locCarriageReturn=chr(13) & chr(10)>

#Replace(qryIngredient.Ingredient,locCarriageReturn, &quot;<li>&quot;,&quot;all&quot;)#



 
Funny this post comes up. I just finished which has an admin area for the author to add recipes. I used a text box and instructed her to seperate ingredients with commas.

Then used the following code to display the indridients in two columns (see: faq232-3697);

Code:
<!--- Use a table--->
<div align=&quot;center&quot;>
<table cellspacing=10 cellpadding=10>
<cfoutput>
<tr>
<!--- Get the ingredients from the list--->
<cfloop list=&quot;#getrecipe.ingredients#&quot; index=&quot;Idx&quot;>
<!--- Start a new row if needed--->
<CFIF listfind(getrecipe.ingredients, #IDX#) MOD NumCols IS 1>
</tr>
<tr>
</CFIF>
<!--- Display the list item --->
<td>#IDX#</td>
</cfloop>
</table>

this will split the list of ingridients into two columns no matter how many were entered.

Hope this helps.


DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
The proper way to do this is with a separate table for ingredients with a foreign key to the recipe table.

How you have the user enter the info is up to you - separate text boxes, one at a time, a textarea with ingredients separated by comma or carriage return, but when you put it in the db, each individual ingredient should go into an ingredients table the is linked to the recipe table.
 
I am new to coldfusion and SQL so would you mind explaing in greater detail, the last post &quot;Postwick&quot;
 
&quot;recipes_Master&quot; would be a table containing recipe name, author, instructions, skill level, time to complete, etc...and a UID(as a key).

recipe_Ingridients would be a table containing a ingredient name and quantity, and also a foriegn key (the ID of a recipe)

The idea is to break down your table structure to the smallest useable levels. You could even have another table called recipes_Steps, making it work very similar to the ingredients table, allowing multiple steps to be formated easier instead of one large text for cooking instructions.

Recipes_Master
__________________________
r_ID | r_Name | r_Author |
--------------------------
2 | Cookies | Kevin |
--------------------------
3 | Cake | joe |
--------------------------

Recipe_Ingredients
___________________________
r_ID | I_Name | I_QTY |
---------------------------
2 | flour | 1 cup |
---------------------------
2 | choc chips | 2 bags |
---------------------------
3 | flour | 2 cups |
---------------------------
3 | eggs | 2 |
---------------------------


hope that makes sense
you don't HAVE to do it this way, but is recomended.


 
Yes...It makes perfect sense...After reading it over a few times that is what I thought it was..and good idea about the instructions, I never thought of that..Doh


Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top