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>

Recommended Answers

All 3 Replies

Member Avatar for diafol

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

thabnks but it still doesn't work..

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.