Newbie Would Appreciate Help With Printing Problem


As I understand it, in order for what I want to happen, I need to print the ID in the link and not the title.

First Table - Recipes:

Columns are:

recipe_id (Set as Primary Key, Auto Increment)

Second Table - Categories:

Columns/values are:

category_id (Values: 1, 2, 3, 4, 5, 6, 7)
category_name (Values: Desserts, Drinks, Fowl, Meat, Pasta, Seafood, Vegetables)

Here’s the scenario:

Jennifer enters the following Recipe into a form on the Desserts Page:

Title: Apple Strudel
Ingredients: Apples, Flour, Water
Prep: Core and slice apples, etc.
Serves: 6
Category: 1

Mary enters the following Recipe into the same form:

Title: Blueberry Pie
Ingredients: Blueberries, Flour, Water
Prep: Wash blueberries, etc.
Serves: 6
Category: 1

The title of each recipe now appears above the form on the Desserts Page, which is what I want.

Linda decides she wants to view each of the recipes, and goes to the Desserts Page. She clicks on Apple Strudel, and the page that’s created shows that recipe. However, when she clicks on “Blueberry Pie,” while the ending of the URL address is recipesdesserts.php?recipeID=1Blueberry (recipesdesserts.php is the display page), the actual page that’s created shows the recipe for the Strudel.

I’ve tried adding some code to Print the Id in the Link and not the Title, but have not had any luck. This is the code that creates the Link from the Title that’s entered:

<?php do { ?><li><a href=“…/Recipes/recipesdesserts.php?recipeID=1<?php echo $row_GetRecipes[‘Title’]; ?>”><strong><?php echo $row_GetRecipes[‘Title’]; ?></strong></a></li><?php } while ($row_GetRecipes =
mysql_fetch_assoc($GetRecipes)); ?>

Could someone please take a look at it, and show me the code additions/corrections that need to be made?

Thank you!


?recipeID=1<?php echo $row_GetRecipes[‘Title’]; ?>

If the id is what you are using to do the lookup, why are you making it so the id in the URL is always 1? Don’t the other recipes have different IDs?

Have you tried recipeID=<?php echo $row_GetRecipes[‘insert-whatever-field-holdstheidhere’]; ?>

Forgive me off I’m way off the mark with what you’re trying to do. :stuck_out_tongue:

All the code was generated by DW CS4.

And given I’m a newbie, I may not be explaining things correctly, and prob a bit lost.

If the id is what you are using to do the lookup, why are you making it so the id in the URL is always 1? Don’t the other recipes have different IDs?

That’s just it. I’m trying to find a way for an end user to be able to click on the Title of any recipe that’s been entered by other end users, and then be taken to the corresponding recipe.

Does that make more sense?

Thank you!


I’m assuming the show recipe page uses the id to know which recipe to load. You following so far? However, in the code loop you posted, the ID is always set to 1. (?recipeID=1) So all the links would always point to the first recipe. What you’ll need to do is replace that literal number 1 with some code that pulls the ID from the database.

Here’s an example from one of my own projects:

while($row = mysql_fetch_assoc($apres))
   ?><a href="/resource.php?id=<?php echo $row['id']; ?>"><?php echo htmlspecialchars($row['title']); ?></a><?php

As you see here, I have id=<?php echo $row[‘id’]; ?>, if this code were to read id=1 then all the links would bring up the first entry.

Edit note: Since this is an example, don’t try to copy and paste any of that and expect it to work. Since you’re a newbie, figured I might need a warning along those lines in here. :smiley:

Edit 2: Unfortunately, I know nothing of how DreamWeaver generates code, so I don’t know how to make DreamWeaver do that.

This is the code (after modifications based on your example). It appears on desserts.php (Form Page), and not the recipesdesserts.php (page that shows the recipe).

<?php do { ?>
<li><a href=“…/Recipes/recipesdesserts.php?recipeID=<?php echo $row[‘id’]; ?>”><strong><?php echo $row_GetRecipes[‘Title’]; ?></strong></a></li>
<?php } while ($row_GetRecipes = mysql_fetch_assoc($GetRecipes)); ?>

I still get the same result no matter which title I click on.

But the ending of the URL is the same for each:


Could there be something wrong w/how the database was set up, or is it still the code?

Sorry, I didn’t add my edit soon enough apparently. Since this is an example, don’t try to copy and paste any of that and expect it to work. Sorry, I wasn’t considering the fact that you were a newbie in my response until much later.

You’ll need to provide the proper variable for your case, which, due to naming differences is not the same as mine. Many apologies.

I don’t know what variable in your case actually holds the database ID. I could guess that it’s something like $row_GetRecipes[‘id’] or $row_GetRecipes[‘Recipe_Id’] or $row_GetRecipes[‘recipe_id’], but with just that code snippet you provided I have no way of knowing the correct variable name to give you. (Which is why I used an example instead of code that would work for you.)

If you can’t figure out the correct variable name to use: I can, if you add <?php var_dump($row_GetRecipes) ?> and copy and paste the messy garbage it outputs here. (Putting it right before the ending </li> would probably be a good place for it.

No worries. And no apologies necessary.

I appreciate, and certainly need all the help I can get.

Here’s what showed up when I previewed in a browser:

Apple Strudelarray(4) { [“Title”]=> string(13) “Apple Strudel” [“Ingredients”]=> string(6) “Apples” [“Prep”]=> string(3) “Mix” [“Serves”]=> string(1) “4” }

Blueberry Piearray(4) { [“Title”]=> string(13) “Blueberry Pie” [“Ingredients”]=> string(11) “Blueberries” [“Prep”]=> string(3) “Mix” [“Serves”]=> string(1) “4” }

Huh!? Weird. It’s not providing it at all!

I wonder why… Any way to tell Dreamweaver to make code that will actually give us the ID for each record? (I don’t want to make you edit more code than is necessary, so it would probably be easier if DreamWeaver provides the ability to include it somehow.)

If it doesn’t we can add a little bit to the select query to actually get it.

Not sure if this helps or not, but I did a search in DW, and under Create Links To The Detail Page, found this:

After building the master page and adding the recordset, you create links that open the detail page. You then modify the links to pass the IDs of the records the user selects. The detail page uses this ID to find the requested record in the database and display it.

Note: You create links to update pages using the same process. The results page is similar to a master page, and the update page is similar to a detail page.

Followed by instructions for:

Open the detail page and pass a record ID (ColdFusion, PHP)

Ah, indeed, this appears to be what I’m talking about. Go ahead and try following the instructions. (5 applies to ColdFusion, so skip that one.) Once you’re done, it should work. The field you’ll want to pass is presumably the recipe_id. Since this part deals specifically with DW, I’m unable to be of much assistance. (If someone is reading this and familiar with DreamWeaver, feel free to jump in!)

Still not working! I even tried building brand new master and detail pages.