0

I'm trying to create something like a breadcrumb based on what is selected from a drop down list. For example if a user selects accessories from a list and then goes on to select from another drop down list scarfs. I want to be able to show:
You selected accessories >> scarfs
somewhere at the bottom of my page. I tried retrieving the selected items using $_POST['item'] and simply printing them with an "echo" but it didn't work. How can this be done? Thanks
Note: The drop down lists are being populated from a database.
This the form code:

<form action="page.php" method = post>
<?php
       echo '<select title="Select one" id="categoriesSelect" name="selectcat">';
       echo '<option value="default"><?php echo ""?></option>';
       while($row1 = $result->fetch_assoc()){            

       echo '<option value="' . $row1['id'] . '">' . $row1['category'] . '</option>';
        }

       echo '</select>';
        ?>

      </div>

      <?php
       echo '<select title="Select one" id="subcatsSelect" name="selectsubcat">';
       echo '<option value="default"><?php echo ""?></option>';
          while($row2 = $result2->fetch_assoc()){


         echo '<option value="' . $row2['subcat'] . '">' . $row2['subcat'] . '</option>';
       }

       echo '</select>';
        ?>
</form>

I'm accessing the select boxes in my script(page.php) like this:

if($_SERVER['REQUEST_METHOD'] == 'POST'){

//get data from forms
$cat = $_POST['selectcat'];
$subcat = $_POST['selectsubcat'];
}

I tried to print the selected items like this:

<div class="here">You selected:</div>
  <div class="product_directory blue"><a href="#"><?php print $cat?></a></div>
  <div class="product_directory arrows">»</div>
  <div class="product_directory blue"><a href="#"><?php print $subcat?></a></div>
  <div style="margin:0 0 -10px 0;"></div>
2
Contributors
3
Replies
18
Views
4 Years
Discussion Span
Last Post by diafol
0

You can do this with js or ajax too.

$breadcrumb='';

if(isset($_POST['cat'])) $breadcrumb .= $_POST['cat'];
if(isset($_POST['subcat'])) $breadcrumb .= ' > ' . $_POST['subcat'];

echo $breadcrumb;

ANyway, you'd probably need to check the validity of the post data before doing this

0

thabnks but it still doesn't work..

Edited by dhani09: improved formatting

0

which bit?
have you got $_POST['cat'] or $_POST['subcat'] ?

Can you echo $_POST['cat'] etc?

If not you're not passing the info properly.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.