Skip to main content
Known Participant
July 4, 2009
Question

PHP/MySQL - Nav links pass variable to another page? Or?

  • July 4, 2009
  • 1 reply
  • 1733 views

I'm a PHP/MySQL beginner. I'm digging through books and tutorials as best I can, but finding myself a little lost in the sheer volume of information. If someone can point me in the right direction for this task, I'd really appreciate it.

I have a database (MySQL) with two tables. One is a list of carpets, and the other a list of the categories of carpets and information about those categories.

The "carpets" table has a field for each record to indicate which category that carpet belongs to.

I'm trying to do this:

- A navigation bar listing the categories

- When you click on a category, a "gallery" page opens, display the carpets (name, description, photo) of each carpet in that category

Does Dreamweaver have server behaviors for this? If not, can anyone give me a general idea of what the code is I need to write to make this happen?

Thanks VERY much in advance,

--
Patty Ayers | www.WebDevBiz.com
Free Articles on the Business of Web Development
Web Design Contract, Estimate Request Form, Estimate Worksheet
--

This topic has been closed for replies.

1 reply

jon8
Inspiring
July 4, 2009

Build your navigation so link goes to a unique page, and on that page a repeat region recordset that pulls all the rugs where category = url variable (?carpet=red)

build the recordset so that it looks for url parameter carpet and the value is = the category in the database.

hope that made sense for you... might be hard to explain over the board.

You might want to also consider merging the two tables together... could make it easier to understand and work with.

P_18Author
Known Participant
July 4, 2009

Jon, thanks very much, see below please.

On Sat, Jul 4, 2009 at 12:56 PM, jon@cmiwebstudio <forums@adobe.com> wrote:

You don't have to use two tables for this. I would consider merging those two tables.

I was thinking about that, but each category has a category description, and I need to sometimes just display the category name, and sometimes display the category description. So don't I need a separate table??

Build your navigation so link goes to a unique page, and on that page a repeat region recordset that pulls all the rugs where category = url variable (?carpet=red)
 
build the recordset so that it looks for url parameter carpet and the value is = the category in the database.

It makes good sense, but I'm not sure of the syntax to write that code, or whether DW can do it for me? I've experimented some, with no success.

Your help is MUCH appreciated,

Patty

David_Powers
Inspiring
July 5, 2009

Using two tables is the correct approach. They should be linked using a foreign key. For example:

categories table

cat_id
categorydescription
1PersianColourful patterned carpets
2AxminsterTraditional British woolen carpets
3NylonCheap and cheerful carpets - mind the static!

carpets table

carpet_id
cat_id
size
price
description
134x650Lurid pink
216x103000Red and blue geometric patterns
314x61500Yellow and green floral pattern

Using this sort of setup, you can create a Recordset in Dreamweaver for the categories table. In the Recordset dialog box, select Simple mode, and select the cat_id and category columns. Set the sort order to category Ascending.

If you call the recordset getCategories, you can use a repeat region to display the results of the recordset.

  1. For the sake of simplicity, create an unordered list, and bind the value of category as the dynamic text in the <li> element.
  2. Select the dynamic text object in Design view. Then click the Browse for folder icon alongside the Link field in the Property inspector.
  3. In the Select File dialog box, select the page where you're going to display the list of carpets in the chosen category.
  4. With the Select File dialog box still open, click the Parameters button.
  5. In the Parameters dialog box that opens, type "cat_id" (without the quotes) in the Name field.
  6. Click the lightning bolt icon to the right of the Value field. This opens a Dynamic Text dialog box.
  7. Select the getCategories recordset, and highlight cat_id.
  8. Click OK three times to close all the dialog boxes.
  9. Select the <li> element in the Tag selector at the bottom of the Document window.
  10. From the Server Behaviors panel menu, select Repeat Region, and set it to repeat all values from the getCategories recordset.

This automatically generates an unordered list with the following HTML and PHP code:

<ul>

<?php do { ?>

  <li><a href="details.php?cat_id=<?php echo $row_getCategories['cat_id']; ?>"><?php echo $row_getCategories['category']; ?></a></li>

<?php } while ($row_getCategories = mysql_fetch_assoc($getCategories)); ?>

When run through the server, each URL will look similar to this: details.php?cat_id=2.

In details.php, you need to create another recordset that uses cat_id to select items from your carpets table.

Dreamweaver can do a lot for you, but this isn't the sort of stuff that you can pick up overnight or learn through quick questions in a forum. The PHP section of my book, "The Essential Guide to Dreamweaver CS4", devotes about 500 pages to working with the Dreamweaver server behaviors.

I know you have got access to the Safari Online Library. I have just discovered that the CS3 version of my book was added last week. The direct Safari link is here. Although I made a lot of improvements in the CS4 book, the basic principles of how the server behaviors work are unchanged between CS3 and CS4.