Skip to main content
Participant
Sep 7, 2012 12:57 PM UTC
Answered

Dynamic select list: link to another page

Hi

Have following dynamic select list at the bottom in "product.php" page (www.dolls.com.sg)

<div id="selectcat">

  <select name="Categories">

    <?php

do { 

?>

    <option value="<?php echo $row_rsCategories['categoryName']?>"<?php if (!(strcmp($row_rsCategories['categoryName'], $row_rsCategories['categoryName']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsCategories['categoryName']?></option>

    <?php

} while ($row_rsCategories = mysql_fetch_assoc($rsCategories));

  $rows = mysql_num_rows($rsCategories);

  if($rows > 0) {

      mysql_data_seek($rsCategories, 0);

   $row_rsCategories = mysql_fetch_assoc($rsCategories);

  }

?>

  </select>

My target is, whenever a visitor clicks on a category in the pull down menu, he is forwarded to the respective "categories.php" page.

How can I do that?

Thanks

Helmut

This topic is closed to new replies. Start a new post to keep the conversation going.
David_Powers
David_PowersCorrect answer
Inspiring
Sep 8, 2012 1:00 PM UTC

Change your code to this:

<div id="selectcat">

<form method="get" action="categories.php">

  <select name="Categories">

    <?php

do { 

?>

    <option value="<?php echo $row_rsCategories['categoryName']?>">

    <?php echo $row_rsCategories['categoryName']?></option>

    <?php

} while ($row_rsCategories = mysql_fetch_assoc($rsCategories));

  $rows = mysql_num_rows($rsCategories);

  if($rows > 0) {

      mysql_data_seek($rsCategories, 0);

   $row_rsCategories = mysql_fetch_assoc($rsCategories);

  }

?>

  </select>

  <input type="submit" value="View Dolls">

</form>

</div>

In categories.php, use $_GET['Categories'] to filter the recordset.

4 replies

David_Powers
David_PowersCorrect answer
Inspiring
Sep 8, 2012 1:00 PM UTC

Change your code to this:

<div id="selectcat">

<form method="get" action="categories.php">

  <select name="Categories">

    <?php

do { 

?>

    <option value="<?php echo $row_rsCategories['categoryName']?>">

    <?php echo $row_rsCategories['categoryName']?></option>

    <?php

} while ($row_rsCategories = mysql_fetch_assoc($rsCategories));

  $rows = mysql_num_rows($rsCategories);

  if($rows > 0) {

      mysql_data_seek($rsCategories, 0);

   $row_rsCategories = mysql_fetch_assoc($rsCategories);

  }

?>

  </select>

  <input type="submit" value="View Dolls">

</form>

</div>

In categories.php, use $_GET['Categories'] to filter the recordset.

Translate
Sentosa99Author
Participant
Sep 9, 2012 12:40 PM UTC

Dear David,

Thanks for the code. It is working now!

Helmut

Translate
Participating Frequently
Sep 7, 2012 7:10 PM UTC

You just need to add some javascript to convert that drop down into a Jump Menu:

http://www.smartwebby.com/web_site_design/jump_menus.asp

Translate
Sentosa99Author
Participant
Sep 8, 2012 7:09 AM UTC

But my target is that with every menu item clicked the visitor is linked to the same "categories.php" page with the respective content from the database for that menu item. I don't see how I can do it with jump menu.

Translate