Nilaab,

This sounds similar to what I was trying to do recently, i.e creating
dependent dropdown boxes.  Here's a link to a demo of the code that might be
of interest to you.
http://www.onlinetools.org/tools/easyselectdata/index.html

Cheers.

Roger

-----Original Message-----
From: @ Nilaab [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 05, 2002 7:36 PM
To: Php-General
Subject: [PHP] Need Redirection Trick...

Hello Everyone,

I have a simple problem that, I think, might require a little trick to be
used. I have a list of products in a database that is organized by
categories and subcategories. Categories can have as many subcategories as
it wants, but some categories don't need to have a subcategory at all.

In the following code "cat" refers to category and "subcat" refers to
subcategory.

cat_data and subcat_data refers to a multi-dimentional array, pulled from
the DB, with values of an id and a name.
example: cat_data[row_number][name_of_category] and
cat_data[row_number][id].

Ok, before I ask the question, here's the code:

[-------------- snip --------------]
<?php
include ("nay_general.php");
include ("$include_path/base_db.class"); // db

$db = new base_db();
$cat_data = $db->get_cat_data();
for ($i=0; $i < count($cat_data); $i++) {
   echo '<a href="' . $PHP_SELF . "?cat_id=" . $cat_data[$i]["id"] . '">' .
$cat_data[$i]["name"] . "</a><br />\n";
   if ($cat_id) {
      $subcat_data = $db->get_subcat_data($cat_id);
      if ($subcat_data != 0 && ($cat_id == $cat_data[$i]["id"])) {
         for ($j=0; $j < count($subcat_data); $j++) {
            echo '&nbsp;&nbsp;&nbsp;&nbsp;- <a href="' . $PHP_SELF .
"?cat_id=$cat_id&subcat_id=" . $subcat_data[$j]["id"] . '">' .
$subcat_data[$j]["name"] . "</a><br />\n";
         }
      }
      elseif ($subcat_data == 0 && ($cat_id == $cat_data[$i]["id"])) {
         $subcat_id = 0;
         header("Location: $PHP_SELF?cat_id=$cat_id&subcat_id=$subcat_id");
      }
   }
}

?>
[-------------- snip --------------]

What this does is it lists all the categories in the database, initially.
When the user clicks on a category, the script will check if the category
has any subcategories associated with it. One of two things should happen
after this.

First, it should list all the subcategories directly below the category it
is associated with, with a little indention to specify that they are
subcategories. The subcategories listed will be a link that passes over the
cat_id and subcat_id GET variables to the same page.

example:        category 1
                category 2
                   - subcategory 1
                   - subcategory 2
                   - subcategory 3
                category 3
                .
                .
                .

This part of the script works fine.

The second thing that should happen is that if there are actually no
subcategories for the selected category then subcat_id should equal 0 and
the script should redirect back to the same page with the GET variables of
cat_id and subcat_id (which is equal to zero at this point). The problem is
that I cannot redirect with a header() function because content is already
sent to the browser at the beginning of the script (the list of categories).
Is there any other way that I can redirect and send the variables of cat_id
and subcat_id to the page in the second situation mentioned earlier?
Register Globals is on.

- Nilaab



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to