Re: [PHP] Need Redirection Trick...

2002-12-05 Thread Jason Wong
On Friday 06 December 2002 11:35, [EMAIL PROTECTED] wrote:
 Hello Everyone,

[lots of irrelevant stuff snipped]

 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.

1) BEFORE you output anything make your check whether you need to redirect. 
After all, if you're going to be redirecting, why output anything at all?

or

2) Use the output buffering functions.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Do not drink coffee in early A.M.  It will keep you awake until noon.
*/


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




RE: [PHP] Need Redirection Trick...

2002-12-05 Thread Roger Lewis
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] . /abr /\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_idsubcat_id= . $subcat_data[$j][id] . '' .
$subcat_data[$j][name] . /abr /\n;
 }
  }
  elseif ($subcat_data == 0  ($cat_id == $cat_data[$i][id])) {
 $subcat_id = 0;
 header(Location: $PHP_SELF?cat_id=$cat_idsubcat_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




RE: [PHP] Need Redirection Trick...

2002-12-05 Thread @ Nilaab
Great Jason, thanks a lot. I was just looking for some direction and I think
you just helped me find it. Thanks for taking the time to look at my
problem.:)

- Nilaab

 -Original Message-
 From: Jason Wong [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, December 05, 2002 11:46 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Need Redirection Trick...


 On Friday 06 December 2002 11:35, [EMAIL PROTECTED] wrote:
  Hello Everyone,

 [lots of irrelevant stuff snipped]

  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.

 1) BEFORE you output anything make your check whether you need to
 redirect.
 After all, if you're going to be redirecting, why output anything at all?

 or

 2) Use the output buffering functions.

 --
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *

 /*
 Do not drink coffee in early A.M.  It will keep you awake until noon.
 */


 --
 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